1use std::borrow::Cow;
2
3use anyhow::{anyhow, Result};
4use gpui::{AssetSource, SharedString};
5use rust_embed::RustEmbed;
6
7#[derive(RustEmbed)]
8#[folder = "../../assets"]
9#[include = "fonts/**/*"]
10#[include = "icons/**/*"]
11#[include = "themes/**/*"]
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<Cow<'static, [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(|p| p.starts_with(path))
27 .map(SharedString::from)
28 .collect())
29 }
30}