pub struct Asset { /* private fields */ }Expand description
An asset containing type information and data.
Assets are the core data containers in the asset system. Each asset has a unique ID, an asset type that defines how to load and save it, and the actual data payload.
Implementations§
Source§impl Asset
impl Asset
Sourcepub fn new(asset_type: Weak<dyn AssetType>, data: Box<dyn AssetData>) -> Self
pub fn new(asset_type: Weak<dyn AssetType>, data: Box<dyn AssetData>) -> Self
Creates a new asset with the given type and data.
The asset ID is initially set to 0 and will be assigned by the asset manager when the asset is registered.
§Arguments
asset_type- The type definition for this assetdata- The actual asset data
Sourcepub fn from_serialized(
mgr: &AssetManager,
serialized: SerializedAsset,
) -> Result<Self, AssetError>
pub fn from_serialized( mgr: &AssetManager, serialized: SerializedAsset, ) -> Result<Self, AssetError>
Creates an asset from a serialized representation.
This method reconstructs an asset from its serialized form by looking up the asset type from the manager and deserializing the data using the appropriate loader.
§Arguments
mgr- The asset manager to use for type lookupserialized- The serialized asset data
§Returns
Ok(Asset) if deserialization succeeds, Err(AssetError) if the asset type
is not found or deserialization fails.
Sourcepub fn asset_type(&self) -> Weak<dyn AssetType>
pub fn asset_type(&self) -> Weak<dyn AssetType>
Returns a clone of the asset type definition.
Auto Trait Implementations§
impl Freeze for Asset
impl !RefUnwindSafe for Asset
impl Send for Asset
impl Sync for Asset
impl Unpin for Asset
impl UnsafeUnpin for Asset
impl !UnwindSafe for Asset
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.