pub struct MaterialCache { /* private fields */ }Expand description
Content-addressable, LRU-evicting cache for PbrMaterial values.
Materials are stored by their structural hash (MaterialKey). When the
cache is full the least-recently-used entry is evicted.
Implementations§
Source§impl MaterialCache
impl MaterialCache
Sourcepub fn insert(&mut self, material: PbrMaterial) -> MaterialKey
pub fn insert(&mut self, material: PbrMaterial) -> MaterialKey
Insert (or refresh) a material. Returns the MaterialKey for later
retrieval. If the cache is full the LRU entry is evicted first.
Sourcepub fn get(&mut self, key: MaterialKey) -> Option<&PbrMaterial>
pub fn get(&mut self, key: MaterialKey) -> Option<&PbrMaterial>
Retrieve a previously inserted material by key.
Sourcepub fn peek(&self, key: MaterialKey) -> Option<&PbrMaterial>
pub fn peek(&self, key: MaterialKey) -> Option<&PbrMaterial>
Peek at a material without updating the LRU counter.
Sourcepub fn remove(&mut self, key: MaterialKey) -> bool
pub fn remove(&mut self, key: MaterialKey) -> bool
Remove a material from the cache.
Sourcepub fn insert_batch(
&mut self,
materials: impl IntoIterator<Item = PbrMaterial>,
) -> Vec<MaterialKey>
pub fn insert_batch( &mut self, materials: impl IntoIterator<Item = PbrMaterial>, ) -> Vec<MaterialKey>
Pre-populate the cache with a slice of materials. Returns the keys.
Sourcepub fn iter(&self) -> impl Iterator<Item = (MaterialKey, &PbrMaterial)>
pub fn iter(&self) -> impl Iterator<Item = (MaterialKey, &PbrMaterial)>
Iterate over all cached materials in arbitrary order.
Auto Trait Implementations§
impl Freeze for MaterialCache
impl RefUnwindSafe for MaterialCache
impl Send for MaterialCache
impl Sync for MaterialCache
impl Unpin for MaterialCache
impl UnsafeUnpin for MaterialCache
impl UnwindSafe for MaterialCache
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
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>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<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>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> 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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.