1use super::*;
2
3#[cfg(not(target_arch = "wasm32"))]
4#[path = "native.rs"]
5mod _impl;
6#[cfg(target_arch = "wasm32")]
7#[path = "web.rs"]
8mod _impl;
9
10pub(crate) use _impl::*;
11
12pub type AssetFuture<T> = Pin<Box<dyn Future<Output = Result<T, Error>>>>;
13
14pub trait LoadAsset: Sized {
15 fn load(geng: &Rc<Geng>, path: &str) -> AssetFuture<Self>;
16 fn default_ext() -> Option<&'static str>;
17}
18
19impl LoadAsset for () {
20 fn load(_: &Rc<Geng>, _: &str) -> AssetFuture<()> {
21 unimplemented!()
22 }
23 fn default_ext() -> Option<&'static str> {
24 None
25 }
26}
27
28impl<T: 'static> LoadAsset for Rc<T>
29where
30 T: LoadAsset,
31{
32 fn load(geng: &Rc<Geng>, path: &str) -> AssetFuture<Self> {
33 T::load(geng, path).map(|t| Ok(Rc::new(t?))).boxed_local()
34 }
35 fn default_ext() -> Option<&'static str> {
36 T::default_ext()
37 }
38}