mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 12:38:02 +00:00
28 lines
543 B
Rust
28 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),
|
||
|
}
|
||
|
}
|
||
|
}
|