lib.rs

 1// This crate was essentially pulled out verbatim from main `zed` crate to avoid having to run RustEmbed macro whenever zed has to be rebuilt. It saves a second or two on an incremental build.
 2use anyhow::anyhow;
 3
 4use gpui::{AssetSource, Result, SharedString};
 5use rust_embed::RustEmbed;
 6
 7#[derive(RustEmbed)]
 8#[folder = "../../assets"]
 9#[include = "fonts/**/*"]
10#[include = "icons/**/*"]
11#[include = "themes/**/*"]
12#[exclude = "themes/src/*"]
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<std::borrow::Cow<'static, [u8]>> {
20        Self::get(path)
21            .map(|f| f.data)
22            .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
23    }
24
25    fn list(&self, path: &str) -> Result<Vec<SharedString>> {
26        Ok(Self::iter()
27            .filter_map(|p| {
28                if p.starts_with(path) {
29                    Some(p.into())
30                } else {
31                    None
32                }
33            })
34            .collect())
35    }
36}