lyra-resource: Make it possible to add resource loaders to the resource manager
This commit is contained in:
parent
52e58b1ca5
commit
67c5876443
|
@ -29,7 +29,7 @@ impl From<io::Error> for LoaderError {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ResourceLoader: Send + Sync {
|
||||
pub trait ResourceLoader {
|
||||
/// Returns the extensions that this loader supports.
|
||||
fn extensions(&self) -> &[&str];
|
||||
/// Returns the mime types that this loader supports.
|
||||
|
|
|
@ -9,7 +9,7 @@ pub enum ResourceState {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Resource<T: Send + Sync + 'static> {
|
||||
pub struct Resource<T> {
|
||||
pub path: String,
|
||||
pub data: Option<Arc<T>>,
|
||||
pub uuid: Uuid,
|
||||
|
@ -19,7 +19,7 @@ pub struct Resource<T: Send + Sync + 'static> {
|
|||
/// A helper type to make it easier to use resources
|
||||
pub type ResHandle<T> = Arc<Resource<T>>;
|
||||
|
||||
impl<T: Send + Sync + 'static> Resource<T> {
|
||||
impl<T> Resource<T> {
|
||||
/// Create the resource with data, its assumed the state is `Ready`
|
||||
pub fn with_data(path: &str, data: T) -> Self {
|
||||
Self {
|
||||
|
|
|
@ -65,6 +65,14 @@ impl ResourceManager {
|
|||
}
|
||||
}
|
||||
|
||||
/// Registers a loader to the manager.
|
||||
pub fn register_loader<L>(&mut self)
|
||||
where
|
||||
L: ResourceLoader + Default + 'static
|
||||
{
|
||||
self.loaders.push(Arc::new(L::default()));
|
||||
}
|
||||
|
||||
pub fn request<T: Send + Sync + Any + 'static>(&mut self, path: &str) -> Result<Arc<Resource<T>>, RequestError> {
|
||||
match self.resources.get(&path.to_string()) {
|
||||
Some(res) => {
|
||||
|
|
Loading…
Reference in New Issue