Skip to main content

gpui_icons_bs/
lib.rs

1use gpui::{AssetSource, Result, SharedString};
2use std::borrow::Cow;
3
4/// Native implementation using RustEmbed
5#[derive(rust_embed::RustEmbed)]
6#[folder = "assets"]
7#[include = "icons/**/*.svg"]
8pub struct Assets;
9
10impl Assets {
11    /// Create a new Assets instance. The endpoint parameter is ignored for native builds.
12    pub fn new(_endpoint: impl Into<SharedString>) -> Self {
13        Self
14    }
15}
16
17impl AssetSource for Assets {
18    fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
19        if path.is_empty() {
20            return Ok(None);
21        }
22
23        Ok(Self::get(path).map(|f| Some(f.data)).ok_or_else(|| {
24            std::io::Error::other(format!("could not find asset at path '{path}'"))
25        })?)
26    }
27
28    fn list(&self, path: &str) -> Result<Vec<SharedString>> {
29        Ok(Self::iter()
30            .filter_map(|p| p.starts_with(path).then(|| p.into()))
31            .collect())
32    }
33}