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