pub struct ResourceManager { /* private fields */ }Expand description
Rust-native resource registry and resource values. Simple resource registry with safe add, replace, remove, and rename operations.
Implementations§
Source§impl ResourceManager
impl ResourceManager
Sourcepub fn get_cloned(&self, id: impl AsRef<str>) -> Option<Resource>
pub fn get_cloned(&self, id: impl AsRef<str>) -> Option<Resource>
Returns a cloned resource by id.
Sourcepub fn get_custom<T>(&self, id: impl AsRef<str>) -> Option<Arc<T>>
pub fn get_custom<T>(&self, id: impl AsRef<str>) -> Option<Arc<T>>
Attempts to downcast a custom resource to a concrete Rust type.
Sourcepub fn require_f32(&self, id: impl AsRef<str>) -> Result<&[f32]>
pub fn require_f32(&self, id: impl AsRef<str>) -> Result<&[f32]>
Returns a shared f32 slice or a type mismatch error.
Sourcepub fn contains(&self, id: impl AsRef<str>) -> bool
pub fn contains(&self, id: impl AsRef<str>) -> bool
Returns true if a resource with the given id exists.
Sourcepub fn insert(
&mut self,
id: impl AsRef<str>,
resource: Resource,
) -> Result<Option<Resource>>
pub fn insert( &mut self, id: impl AsRef<str>, resource: Resource, ) -> Result<Option<Resource>>
Inserts or replaces a resource.
Sourcepub fn add(&mut self, id: impl AsRef<str>, resource: Resource) -> Result<()>
pub fn add(&mut self, id: impl AsRef<str>, resource: Resource) -> Result<()>
Adds a resource if the id is unused.
Sourcepub fn replace(
&mut self,
id: impl AsRef<str>,
resource: Resource,
) -> Result<Resource>
pub fn replace( &mut self, id: impl AsRef<str>, resource: Resource, ) -> Result<Resource>
Replaces an existing resource.
Sourcepub fn remove(&mut self, id: impl AsRef<str>) -> Result<Resource>
pub fn remove(&mut self, id: impl AsRef<str>) -> Result<Resource>
Removes a resource from the registry.
Sourcepub fn rename(
&mut self,
from: impl AsRef<str>,
to: impl AsRef<str>,
) -> Result<()>
pub fn rename( &mut self, from: impl AsRef<str>, to: impl AsRef<str>, ) -> Result<()>
Renames a resource identifier without changing the underlying value.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&ResourceId, &Resource)>
pub fn iter(&self) -> impl Iterator<Item = (&ResourceId, &Resource)>
Returns an iterator over all registered ids and resources.
Sourcepub fn snapshot(&self) -> Vec<(ResourceId, Resource)>
pub fn snapshot(&self) -> Vec<(ResourceId, Resource)>
Returns a cloned snapshot of all registered resources.
Sourcepub fn prune_except<I, S>(&mut self, keep: I) -> Vec<(ResourceId, Resource)>
pub fn prune_except<I, S>(&mut self, keep: I) -> Vec<(ResourceId, Resource)>
Removes every resource whose id is not listed in keep.
Trait Implementations§
Source§impl Clone for ResourceManager
impl Clone for ResourceManager
Source§fn clone(&self) -> ResourceManager
fn clone(&self) -> ResourceManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ResourceManager
impl Debug for ResourceManager
Source§impl Default for ResourceManager
impl Default for ResourceManager
Source§fn default() -> ResourceManager
fn default() -> ResourceManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ResourceManager
impl !RefUnwindSafe for ResourceManager
impl Send for ResourceManager
impl Sync for ResourceManager
impl Unpin for ResourceManager
impl !UnwindSafe for ResourceManager
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