BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / assets.rs

assets.rs

62bd9112 History
assets.rs 1.3 KiB Download Raw
1use std::borrow::Cow;
2
3use gpui_kit::{AssetSource, Result, SharedString};
4
5macro_rules! symbols {
6 ($($name:literal),* $(,)?) => {
7 [$((concat!("symbols/", $name, ".svg"), include_bytes!(concat!("../assets/symbols/", $name, ".svg")) as &[u8])),*]
8 };
9}
10
11const SYMBOLS: [(&str, &[u8]); 23] = symbols![
12 "done",
13 "done_all",
14 "keyboard_return",
15 "schedule",
16 "close",
17 "reply",
18 "group",
19 "tag",
20 "image",
21 "check_circle",
22 "error",
23 "notifications",
24 "content_copy",
25 "attach_file",
26 "upload",
27 "download",
28 "folder_open",
29 "refresh",
30 "code",
31 "link",
32 "format_list_bulleted",
33 "format_list_numbered",
34 "format_quote",
35];
36
37pub struct AppAssets;
38
39impl AssetSource for AppAssets {
40 fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
41 if let Some((_, bytes)) = SYMBOLS.iter().find(|(name, _)| *name == path) {
42 return Ok(Some(Cow::Borrowed(bytes)));
43 }
44 gpui_kit::assets::AllAssets.load(path)
45 }
46
47 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
48 let mut names = gpui_kit::assets::AllAssets.list(path)?;
49 names.extend(
50 SYMBOLS
51 .iter()
52 .filter(|(name, _)| name.starts_with(path))
53 .map(|(name, _)| SharedString::from(*name)),
54 );
55 Ok(names)
56 }
57}