1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use crate::Result;
pub use self::dir::Directory;
mod dir;
/// A trait for asset sources, which provides
/// methods for loading bytes.
pub trait Source: Send + Sync + 'static {
/// This is called to check if an asset has been modified.
///
/// Returns the modification time as seconds since `UNIX_EPOCH`.
fn modified(&self, path: &str) -> Result<u64>;
/// Loads the bytes given a path.
///
/// The id should always use `/` as separator in paths.
fn load(&self, path: &str) -> Result<Vec<u8>>;
/// Returns both the result of `load` and `modified` as a tuple.
/// There's a default implementation which just calls both methods,
/// but you may be able to provide a more optimized version yourself.
fn load_with_metadata(&self, path: &str) -> Result<(Vec<u8>, u64)> {
#[cfg(feature = "profiler")]
profile_scope!("source_load_asset_with_metadata");
let m = self.modified(path)?;
let b = self.load(path)?;
Ok((b, m))
}
}