ZIm/gpui/src/assets.rs
2021-03-18 13:13:31 -06:00

27 lines
543 B
Rust

use anyhow::{anyhow, Result};
use std::borrow::Cow;
pub trait AssetSource: 'static {
fn load(&self, path: &str) -> Result<Cow<[u8]>>;
}
impl AssetSource for () {
fn load(&self, path: &str) -> Result<Cow<[u8]>> {
Err(anyhow!(
"get called on empty asset provider with \"{}\"",
path
))
}
}
pub struct AssetCache {
source: Box<dyn AssetSource>,
}
impl AssetCache {
pub fn new(source: impl AssetSource) -> Self {
Self {
source: Box::new(source),
}
}
}