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#[exclude = "*.DS_Store"]
11pub struct Assets;
12
13impl AssetSource for Assets {
14 fn load(&self, path: &str) -> Result<Cow<'static, [u8]>> {
15 Self::get(path)
16 .map(|f| f.data)
17 .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
18 }
19
20 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
21 Ok(Self::iter()
22 .filter(|p| p.starts_with(path))
23 .map(SharedString::from)
24 .collect())
25 }
26}