assets.rs

 1use anyhow::{anyhow, Result};
 2use gpui::AssetSource;
 3use rust_embed::RustEmbed;
 4
 5#[derive(RustEmbed)]
 6#[folder = "../../assets"]
 7#[exclude = "*.DS_Store"]
 8pub struct Assets;
 9
10impl AssetSource for Assets {
11    fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
12        Self::get(path)
13            .map(|f| f.data)
14            .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
15    }
16
17    fn list(&self, path: &str) -> Vec<std::borrow::Cow<'static, str>> {
18        Self::iter().filter(|p| p.starts_with(path)).collect()
19    }
20}