1use anyhow::anyhow;
2
3use gpui::{AssetSource, Result, SharedString};
4use rust_embed::RustEmbed;
5
6#[derive(RustEmbed)]
7#[folder = "../../assets"]
8#[include = "fonts/**/*"]
9#[include = "icons/**/*"]
10#[include = "themes/**/*"]
11#[exclude = "themes/src/*"]
12#[include = "sounds/**/*"]
13#[include = "*.md"]
14#[exclude = "*.DS_Store"]
15pub struct Assets;
16
17impl AssetSource for Assets {
18 fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
19 Self::get(path)
20 .map(|f| f.data)
21 .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
22 }
23
24 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
25 Ok(Self::iter()
26 .filter_map(|p| {
27 if p.starts_with(path) {
28 Some(p.into())
29 } else {
30 None
31 }
32 })
33 .collect())
34 }
35}