pub struct AssetManager { /* private fields */ }Expand description
Central manager for assets in the system.
The asset manager is responsible for:
- Registering and retrieving asset types
- Managing asset lifecycles and hash-based unique IDs
- Providing access to the filesystem for asset operations
- Thread-safe storage of assets and their metadata
Implementations§
Source§impl AssetManager
impl AssetManager
Sourcepub fn new(filesystem: Arc<dyn Filesystem>) -> Self
pub fn new(filesystem: Arc<dyn Filesystem>) -> Self
Creates a new asset manager with the provided filesystem.
§Arguments
filesystem- The filesystem implementation to use for asset I/O
Sourcepub fn context(&self) -> Option<Arc<dyn AssetManagerContext>>
pub fn context(&self) -> Option<Arc<dyn AssetManagerContext>>
Retrieves the current asset manager context.
§Returns
The context if one has been set, otherwise None.
Sourcepub fn set_context(&mut self, context: Arc<dyn AssetManagerContext>)
pub fn set_context(&mut self, context: Arc<dyn AssetManagerContext>)
Sourcepub fn set_serialization_backend(
&mut self,
serialization: Box<dyn AssetSerializationBackend>,
)
pub fn set_serialization_backend( &mut self, serialization: Box<dyn AssetSerializationBackend>, )
Sets the serialization backend for the asset manager.
This allows changing how assets are serialized and deserialized. The backend determines the format used for asset persistence.
§Arguments
serialization- The serialization backend implementation to use
Sourcepub fn register_asset_type(&self, asset_type: Arc<dyn AssetType>)
pub fn register_asset_type(&self, asset_type: Arc<dyn AssetType>)
Registers a new asset type with the manager.
This allows the asset manager to handle assets of this type. If an asset type with the same name already exists, it will be replaced.
§Arguments
asset_type- The asset type implementation to register
Sourcepub fn register_asset(&self, asset_path: &str, asset: Asset) -> AssetId
pub fn register_asset(&self, asset_path: &str, asset: Asset) -> AssetId
Registers an asset with the manager and assigns it a deterministic ID.
If the asset’s ID is non-zero, the ID is generated from the asset path using hash-based generation, ensuring the same path always produces the same ID.
§Arguments
asset_path- The path string used to generate the asset IDasset- The asset to register
§Returns
The deterministic ID assigned to the asset
Sourcepub fn unregister_asset(&self, id: AssetId) -> bool
pub fn unregister_asset(&self, id: AssetId) -> bool
Unregisters an asset from the manager.
Removes the asset with the given ID from the manager’s storage. The asset will no longer be accessible through the manager after this call. The asset will be de-allocated when all Arc references to it are dropped.
§Arguments
id- The unique identifier of the asset to remove
§Returns
true if the asset was found and removed, false if no asset with that ID existed.
Sourcepub async fn fs_read_bytes(
&self,
asset_path: &str,
) -> Result<Vec<u8>, FilesystemError>
pub async fn fs_read_bytes( &self, asset_path: &str, ) -> Result<Vec<u8>, FilesystemError>
Asynchronously reads the raw bytes of a file from the filesystem.
This is a convenience method that delegates to the underlying filesystem for reading asset files as byte arrays. The operation is non-blocking.
§Arguments
asset_path- The path to the file to read
§Returns
A future that resolves to the file contents as bytes, or a FilesystemError if reading fails.
Sourcepub async fn fs_read_and_register_asset(
&self,
asset_path: &str,
) -> Result<AssetId>
pub async fn fs_read_and_register_asset( &self, asset_path: &str, ) -> Result<AssetId>
Asynchronously reads an asset file and registers it with the manager.
This method combines file reading with asset deserialization and registration. It reads the asset file from the filesystem, deserializes it using the configured serialization backend, and registers the resulting asset with the manager. If the asset has no ID (ID is 0), it generates one deterministically from the path.
§Arguments
asset_path- The path to the asset file to read and register
§Returns
A future that resolves to the asset ID if successful, or an error if reading, deserialization, or asset creation fails.
§Errors
This function will return an error if:
- The file cannot be read from the filesystem
- The file contents cannot be deserialized
- Asset creation from the serialized data fails
Auto Trait Implementations§
impl !Freeze for AssetManager
impl !RefUnwindSafe for AssetManager
impl Send for AssetManager
impl Sync for AssetManager
impl Unpin for AssetManager
impl UnsafeUnpin for AssetManager
impl !UnwindSafe for AssetManager
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
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>
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>
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)
&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)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.