pub struct AssetResult<A> { /* private fields */ }Implementations§
Source§impl<A> AssetResult<A>where
A: Asset,
impl<A> AssetResult<A>where
A: Asset,
Sourcepub fn build_optional<B>(
&mut self,
builder: &mut B,
) -> Result<Option<&A>, Error>where
A: AssetBuild<B>,
pub fn build_optional<B>(
&mut self,
builder: &mut B,
) -> Result<Option<&A>, Error>where
A: AssetBuild<B>,
Builds and returns asset.
Returns Err if asset decoding or build errors.
Returns Ok(None) if asset is not found.
Sourcepub fn build<B>(&mut self, builder: &mut B) -> Result<&A, Error>where
A: AssetBuild<B>,
pub fn build<B>(&mut self, builder: &mut B) -> Result<&A, Error>where
A: AssetBuild<B>,
Builds and returns asset.
Returns Err if asset decoding or build errors or if asset is not found.
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}Auto Trait Implementations§
impl<A> !RefUnwindSafe for AssetResult<A>
impl<A> !UnwindSafe for AssetResult<A>
impl<A> Freeze for AssetResult<A>where
A: Freeze,
impl<A> Send for AssetResult<A>where
A: Send,
impl<A> Sync for AssetResult<A>where
A: Sync,
impl<A> Unpin for AssetResult<A>where
A: Unpin,
impl<A> UnsafeUnpin for AssetResult<A>where
A: UnsafeUnpin,
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