Crate mini_asset_loader

Source
Expand description

The mini asset loader provides a simple set of utilities to enable the loading of assets by their name for use in, e.g., a game.

§Loaders

  • The loaders::CachedLoader provides the ability to cache assets in-memory between loads, with full user control over when unused assets are unloaded. The loaders::ToCached trait, which is implemented for all loaders, allows you to use to_cached() to convert a loader into a cached one.
  • A simple Vec<Box<dyn AssetLoader>> can search multiple loaders and load the first successful result, which is made easier via the provided asset_loader_vec! macro.
  • A PathBuf acts as a loader to load assets from a specific path on disk.
  • The [loaders::ZipLoader] can load assets from a ZIP file.
  • A simple HashMap can be used as a loader for assets stored in memory. These loaders can be composed in various ways to create more advanced behaviour.

§Asset Creation Handlers

An AssetCreationHandler implementation is required - this provides the function that actually creates an asset, meaning this is the ideal place to implement custom deserialization, allocation, etc. for your custom asset type.

For a simple implementation of this, which provides a helpful example of the asset system in use, (but which, unfortunately, requires nightly rust), see the [asset] module.

The ExtensionMappedAssetCreationHandler is a builtin type that allows one to map different file extensions on the asset identifier string to different AssetCreationHandlers. For example, one could use the builtin asset module’s creation handler for .json-based types, and use a separate mesh creation handler for .dae types.

§Features

  • zip - Provides the [loaders::zip] module, containing a ZIP file loader.
  • asset - Provides the [asset] module, containing a simple JSON asset implementation.

Modules§

loaders
Some basic types of AssetLoader.

Macros§

asset_loader_vec
Allows for easy creation of a vector of boxed asset loaders. Use it the same as you would use vec!. Each element will be passed through Box::new.

Structs§

AnyHandle
A thread-safe shared pointer to a value of any Any type, allowing for downcasting.
ExtensionMappedAssetCreationHandler
Maps to multiple AssetCreationHandlers based on the file extension of the asset.

Traits§

AssetCreationHandler
An AssetCreationHandler is a delegate that handles the creation (usually deserialization) and allocation of assets from an input byte stream.
AssetLoader
An AssetLoader loads an asset given its name, with help from an AssetCreationHandler. Some AssetLoaders implement special behaviour, such as caching or combining multiple child loaders.
TypedAssetLoader
A TypedAssetLoader is a simple helper for AssetLoaders that can downcast them into a handle matching their type.