Struct AssetLibrary

Source
pub struct AssetLibrary {
    version: Version,
    registered_packs: HashMap<String, AssetLibraryEntry>,
    loaded_packs: HashMap<String, AssetPack>,
}
Expand description

An AssetLibrary is a device-wide registry of packs that save files can refer to. It handles as the bridge between relative paths within an asset pack and the actual paths on a user’s device.

Fields§

§version: Version

The version of the software that last touched the library, used to help with future migrations.

§registered_packs: HashMap<String, AssetLibraryEntry>

A map of asset packs, keyed by their (public) identifiers.

§loaded_packs: HashMap<String, AssetPack>

A map of currently loaded asset packs, keyed by their (public) identifiers.

Given that this map is only persisted for the runtime of the application, it’s possible that an AssetPack is ‘known’ but not loaded.

Implementations§

Source§

impl AssetLibrary

Source

pub fn load_or_default(path: Option<PathBuf>) -> Result<Self, AssetLibraryError>

Attempts to AssetLibrary::load the library from path, and returns the default value on [IOError].

Any other error will be propagated by this method.

§Errors

See AssetLibrary::load.

Source

pub fn load(path: Option<PathBuf>) -> Result<Self, AssetLibraryError>

Attempts to load the asset library from path, where path is the configuration directory. If None is passed, the [utils::config_path] method is used instead.

§Errors

An error can be returned for the following situations:

Source

pub fn delete(&mut self) -> Result<(), AssetLibraryError>

Recursively removes all cache and config of all packs and the library itself. To clean up a specific AssetPack, use AssetLibrary::delete_pack.

§Errors

See errors returned by AssetLibrary::delete_pack.

Source

pub fn delete_pack(&mut self, id: &String) -> Result<(), AssetLibraryError>

Attempts to delete cache and config files of a given AssetPack and then unregisters it from the library.

§Errors

If any IO related errors occur while removing the pack, this method can return a AssetLibraryError::OpenAssetPack.

Source

pub fn save(&self, path: Option<PathBuf>) -> Result<(), AssetLibraryError>

Saves the asset library.

§Errors

An error can be returned for the following situations:

Source

pub fn add_pack( &mut self, root: &Path, name: Option<String>, ) -> Result<String, AssetLibraryError>

Registers a new AssetPack in the library and returns the AssetPack’s ID.

Note that you should only use this to create a new pack, not to load an existing one.

§Errors
Source

pub fn load_pack( &mut self, id: &String, ) -> Result<&mut AssetPack, AssetLibraryError>

Attempt to load a previously registered AssetPack.

§Errors
Source

pub fn is_pack_loaded(&self, id: &String) -> bool

Adds a method to check if a given AssetPack is already loaded in the current library.

Source

pub fn is_pack_registered(&self, id: &String) -> bool

Checks whether an asset pack is “known” (registered) within the current asset library.

You can register new asset packs using AssetLibrary::add_pack.

Source

pub fn get_pack(&self, id: &String) -> Option<&AssetPack>

Attempts to retrieve an previously loaded AssetPack from the current library.

If None is returned the pack either doesn’t exist or hasn’t been loaded yet (see AssetLibrary::load_pack).

Source

pub fn get_pack_mut(&mut self, id: &String) -> Option<&mut AssetPack>

Attempts to retrieve an previously loaded AssetPack from the current library.

If None is returned the pack either doesn’t exist or hasn’t been loaded yet (see AssetLibrary::load_pack).

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &PathBuf)>

Iterator over all registered packs.

Source

fn get_path(path: Option<PathBuf>) -> Result<PathBuf, AssetLibraryError>

Either returns path or config_path() if path is None.

§Errors

Returns an error if the configuration folder cannot be found.

Trait Implementations§

Source§

impl Debug for AssetLibrary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AssetLibrary

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AssetLibrary

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AssetLibrary

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Resource for AssetLibrary
where Self: Send + Sync + 'static,

Auto Trait Implementations§

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
§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: 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.
§

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.
§

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.
§

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.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using default().

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,