Skip to main content

AssetResult

Struct AssetResult 

Source
pub struct AssetResult<A> { /* private fields */ }

Implementations§

Source§

impl<A> AssetResult<A>
where A: Asset,

Source

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.

Source

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}
Source

pub fn get_optional(&mut self) -> Result<Option<&A>, Error>
where A: TrivialAssetBuild,

Returns asset. Returns Err if asset decoding or build errors. This function is only usable for TrivialAssetBuild implementors. All TrivialAssets implement TrivialAssetBuild.

Source

pub fn get(&mut self) -> Result<&A, Error>
where A: TrivialAssetBuild,

Returns asset. Returns Err if asset decoding or build errors or if asset is not found. This function is only usable for TrivialAssetBuild implementors. All TrivialAssets implement TrivialAssetBuild.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.