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#[include = "sounds/**/*"]
12#[include = "*.md"]
13#[exclude = "*.DS_Store"]
14pub struct Assets;
15
16impl AssetSource for Assets {
17 fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
18 Self::get(path)
19 .map(|f| f.data)
20 .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
21 }
22
23 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
24 Ok(Self::iter()
25 .filter_map(|p| {
26 if p.starts_with(path) {
27 Some(p.into())
28 } else {
29 None
30 }
31 })
32 .collect())
33 }
34}