gpui-component/crates/story/src/assets.rs
Carlo Corradini 908c022efe
chore: Assets interpolate folder path via rust embed (#1318)
Use `rust-embed` feature `interpolate-folder-path` to always
(`debug`/`release`) load assets from the correct `assets` directory
2025-10-02 16:04:33 +08:00

27 lines
735 B
Rust

use anyhow::anyhow;
use gpui::{AssetSource, Result, SharedString};
use rust_embed::RustEmbed;
use std::borrow::Cow;
#[derive(RustEmbed)]
#[folder = "$CARGO_MANIFEST_DIR/../../assets"]
#[include = "icons/**/*.svg"]
pub struct Assets;
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
if path.is_empty() {
return Ok(None);
}
Self::get(path)
.map(|f| Some(f.data))
.ok_or_else(|| anyhow!("could not find asset at path \"{path}\""))
}
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
Ok(Self::iter()
.filter_map(|p| p.starts_with(path).then(|| p.into()))
.collect())
}
}