Skip to main content

gpui_kit_assets/
native_assets.rs

1use anyhow::anyhow;
2use gpui::{AssetSource, Result, SharedString};
3use std::borrow::Cow;
4
5include!(concat!(env!("OUT_DIR"), "/default_assets.rs"));
6
7/// Explicitly embed the complete Lucide and GPUI Kit icon catalog.
8#[derive(rust_embed::RustEmbed)]
9#[folder = "assets"]
10#[include = "icons/**/*.svg"]
11pub struct AllAssets;
12
13macro_rules! impl_asset_source {
14    ($name:ident) => {
15        impl $name {
16            /// Create an asset source. The endpoint is ignored on native platforms.
17            pub fn new(_endpoint: impl Into<SharedString>) -> Self {
18                Self
19            }
20        }
21
22        impl AssetSource for $name {
23            fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
24                if path.is_empty() {
25                    return Ok(None);
26                }
27                Self::get(path)
28                    .map(|file| Some(file.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(|name| name.starts_with(path).then(|| name.into()))
35                    .collect())
36            }
37        }
38    };
39}
40
41impl_asset_source!(Assets);
42impl_asset_source!(AllAssets);