gpui_component_assets/
lib.rs1use anyhow::anyhow;
2use gpui::{AssetSource, Result, SharedString};
3use rust_embed::RustEmbed;
4use std::borrow::Cow;
5
6#[derive(RustEmbed)]
17#[folder = "assets"]
18#[include = "icons/**/*.svg"]
19pub struct Assets;
20
21impl AssetSource for Assets {
22 fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
23 if path.is_empty() {
24 return Ok(None);
25 }
26
27 Self::get(path)
28 .map(|f| Some(f.data))
29 .ok_or_else(|| anyhow!("could not find asset at path \"{path}\""))
30 }
31
32 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
33 Ok(Self::iter()
34 .filter_map(|p| p.starts_with(path).then(|| p.into()))
35 .collect())
36 }
37}