assets.rs

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