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
impl AssetLibrary
Sourcepub fn load_or_default(path: Option<PathBuf>) -> Result<Self, AssetLibraryError>
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
.
Sourcepub fn load(path: Option<PathBuf>) -> Result<Self, AssetLibraryError>
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:
- The configuration folder could not be retrieved:
AssetLibraryError::LocateConfigFolder
- An error occurs while trying to read the config file (doesn’t exist, permissions, …):
AssetLibraryError::LocateConfigFolder
- The file was found, could be read but failed to deserialize: [
AssetLibraryError::Serialization
].
Sourcepub fn delete(&mut self) -> Result<(), AssetLibraryError>
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
.
Sourcepub fn delete_pack(&mut self, id: &String) -> Result<(), AssetLibraryError>
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
.
Sourcepub fn save(&self, path: Option<PathBuf>) -> Result<(), AssetLibraryError>
pub fn save(&self, path: Option<PathBuf>) -> Result<(), AssetLibraryError>
Saves the asset library.
§Errors
An error can be returned for the following situations:
- The configuration folder could not be retrieved:
AssetLibraryError::LocateConfigFolder
- An error occurs while trying to read the config file (doesn’t exist, permissions, …):
AssetLibraryError::LocateConfigFolder
- The file was found, could be read but failed to deserialize: [
AssetLibraryError::Serialization
].
Sourcepub fn add_pack(
&mut self,
root: &Path,
name: Option<String>,
) -> Result<String, AssetLibraryError>
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
- The configuration folder could not be retrieved:
AssetLibraryError::LocateConfigFolder
- An error occurs while trying to read the config file (doesn’t exist, permissions, …):
AssetLibraryError::LocateConfigFolder
- The file was found, could be read but failed to deserialize: [
AssetLibraryError::Serialization
].
Sourcepub fn load_pack(
&mut self,
id: &String,
) -> Result<&mut AssetPack, AssetLibraryError>
pub fn load_pack( &mut self, id: &String, ) -> Result<&mut AssetPack, AssetLibraryError>
Attempt to load a previously registered AssetPack
.
§Errors
- If the asset pack isn’t previously registered using
AssetLibrary::add_pack
this method returnsAssetLibraryError::NotFound
. - If an error occurs while loading the
AssetPack
, it returnsAssetLibraryError::OpenAssetPack
.
Sourcepub fn is_pack_loaded(&self, id: &String) -> bool
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.
Sourcepub fn is_pack_registered(&self, id: &String) -> bool
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
.
Sourcepub fn get_pack(&self, id: &String) -> Option<&AssetPack>
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
).
Sourcepub fn get_pack_mut(&mut self, id: &String) -> Option<&mut AssetPack>
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
).
Trait Implementations§
Source§impl Debug for AssetLibrary
impl Debug for AssetLibrary
Source§impl Default for AssetLibrary
impl Default for AssetLibrary
Source§impl<'de> Deserialize<'de> for AssetLibrary
impl<'de> Deserialize<'de> for AssetLibrary
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for AssetLibrary
impl Serialize for AssetLibrary
impl Resource for AssetLibrary
Auto Trait Implementations§
impl Freeze for AssetLibrary
impl RefUnwindSafe for AssetLibrary
impl Send for AssetLibrary
impl Sync for AssetLibrary
impl Unpin for AssetLibrary
impl UnwindSafe for AssetLibrary
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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