zed/crates/storybook/src/assets.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
832 B
Rust
Raw Normal View History

2023-10-04 08:51:47 +00:00
use std::borrow::Cow;
use anyhow::{anyhow, Result};
use gpui::{AssetSource, SharedString};
2023-10-04 08:51:47 +00:00
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "../../assets"]
#[include = "fonts/**/*"]
#[include = "icons/**/*"]
#[include = "images/**/*"]
2023-10-04 08:51:47 +00:00
#[include = "themes/**/*"]
#[include = "sounds/**/*"]
#[include = "*.md"]
#[exclude = "*.DS_Store"]
pub struct Assets;
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
Self::get(path)
2023-10-04 08:51:47 +00:00
.map(|f| f.data)
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
.map(Some)
2023-10-04 08:51:47 +00:00
}
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
2023-10-04 08:51:47 +00:00
Ok(Self::iter()
.filter(|p| p.starts_with(path))
2023-10-04 08:51:47 +00:00
.map(SharedString::from)
.collect())
}
}