pub struct Loader { /* private fields */ }Expand description
Virtual storage for all available assets.
Implementations§
Source§impl Loader
impl Loader
Sourcepub fn builder() -> LoaderBuilder
pub fn builder() -> LoaderBuilder
Returns LoaderBuilder instance
Examples found in repository?
examples/proc.rs (line 157)
123async fn run() -> Result<(), Box<dyn std::error::Error>> {
124 // Fill map.
125 let source = HashMapSource(
126 vec![
127 (
128 AssetId::new(2).unwrap(),
129 b"null".to_vec().into_boxed_slice(),
130 ),
131 (
132 AssetId::new(3).unwrap(),
133 b"{\"field\": {}}".to_vec().into_boxed_slice(),
134 ),
135 (
136 AssetId::new(4).unwrap(),
137 b"{\"a\": 3}".to_vec().into_boxed_slice(),
138 ),
139 (
140 AssetId::new(5).unwrap(),
141 b"{\"c\": {\"a\": 2}, \"a\": 3}".to_vec().into_boxed_slice(),
142 ),
143 (
144 AssetId::new(6).unwrap(),
145 b"{\"wrapped\": 42}".to_vec().into_boxed_slice(),
146 ),
147 (
148 AssetId::new(7).unwrap(),
149 b"{\"a\": 6}".to_vec().into_boxed_slice(),
150 ),
151 (AssetId::new(8).unwrap(), b"{}".to_vec().into_boxed_slice()),
152 ]
153 .into_iter()
154 .collect(),
155 );
156
157 let loader = Loader::builder().with(source).build();
158
159 let _: &UnitAsset = loader.load("2").await.build(&mut ())?;
160 println!("UnitAsset loaded");
161
162 let _: &SimpleAsset = loader.load("3").await.build(&mut ())?;
163 println!("SimpleAsset loaded");
164
165 let _: &TwoLevelAsset = loader.load("4").await.build(&mut ())?;
166 println!("TwoLevelAsset loaded");
167
168 let _: &ComplexAsset = loader.load("5").await.build(&mut ())?;
169 println!("ComplexAsset loaded");
170
171 let _: &WrapperAsset = loader.load("6").await.build(&mut ())?;
172 println!("WrapperAsset loaded");
173
174 let _: &AssetWithWrapper = loader.load("7").await.build(&mut ())?;
175 println!("AssetWithWrapper loaded");
176
177 let _: &AssetWithSerdeAttribute = loader.load("8").await.build(&mut ())?;
178 println!("AssetWithSerdeAttribute loaded");
179
180 let _: &AssetWithOption = loader.load("8").await.build(&mut ())?;
181 println!("AssetWithOption loaded");
182
183 Ok(())
184}Sourcepub fn load_typed<A>(&self, id: TypedAssetId<A>) -> AssetHandle<A> ⓘwhere
A: Asset,
pub fn load_typed<A>(&self, id: TypedAssetId<A>) -> AssetHandle<A> ⓘwhere
A: Asset,
Load asset with specified id and returns handle that can be used to access assets once it is loaded.
If asset was previously requested it will not be re-loaded, but handle to shared state will be returned instead, even if first load was not successful or different format was used.
Sourcepub fn load<'a, A, K>(&self, key: K) -> AssetHandle<A> ⓘ
pub fn load<'a, A, K>(&self, key: K) -> AssetHandle<A> ⓘ
Load asset with specified key (path or id) and returns handle that can be used to access assets once it is loaded.
If asset was previously requested it will not be re-loaded, but handle to shared state will be returned instead, even if first load was not successful or different format was used.
Examples found in repository?
examples/proc.rs (line 159)
123async fn run() -> Result<(), Box<dyn std::error::Error>> {
124 // Fill map.
125 let source = HashMapSource(
126 vec![
127 (
128 AssetId::new(2).unwrap(),
129 b"null".to_vec().into_boxed_slice(),
130 ),
131 (
132 AssetId::new(3).unwrap(),
133 b"{\"field\": {}}".to_vec().into_boxed_slice(),
134 ),
135 (
136 AssetId::new(4).unwrap(),
137 b"{\"a\": 3}".to_vec().into_boxed_slice(),
138 ),
139 (
140 AssetId::new(5).unwrap(),
141 b"{\"c\": {\"a\": 2}, \"a\": 3}".to_vec().into_boxed_slice(),
142 ),
143 (
144 AssetId::new(6).unwrap(),
145 b"{\"wrapped\": 42}".to_vec().into_boxed_slice(),
146 ),
147 (
148 AssetId::new(7).unwrap(),
149 b"{\"a\": 6}".to_vec().into_boxed_slice(),
150 ),
151 (AssetId::new(8).unwrap(), b"{}".to_vec().into_boxed_slice()),
152 ]
153 .into_iter()
154 .collect(),
155 );
156
157 let loader = Loader::builder().with(source).build();
158
159 let _: &UnitAsset = loader.load("2").await.build(&mut ())?;
160 println!("UnitAsset loaded");
161
162 let _: &SimpleAsset = loader.load("3").await.build(&mut ())?;
163 println!("SimpleAsset loaded");
164
165 let _: &TwoLevelAsset = loader.load("4").await.build(&mut ())?;
166 println!("TwoLevelAsset loaded");
167
168 let _: &ComplexAsset = loader.load("5").await.build(&mut ())?;
169 println!("ComplexAsset loaded");
170
171 let _: &WrapperAsset = loader.load("6").await.build(&mut ())?;
172 println!("WrapperAsset loaded");
173
174 let _: &AssetWithWrapper = loader.load("7").await.build(&mut ())?;
175 println!("AssetWithWrapper loaded");
176
177 let _: &AssetWithSerdeAttribute = loader.load("8").await.build(&mut ())?;
178 println!("AssetWithSerdeAttribute loaded");
179
180 let _: &AssetWithOption = loader.load("8").await.build(&mut ())?;
181 println!("AssetWithOption loaded");
182
183 Ok(())
184}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Loader
impl !UnwindSafe for Loader
impl Freeze for Loader
impl Send for Loader
impl Sync for Loader
impl Unpin for Loader
impl UnsafeUnpin for Loader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more