pub struct ChunkCache { /* private fields */ }Expand description
LRU cache for terrain chunks.
Implementations§
Source§impl ChunkCache
impl ChunkCache
pub fn new(max_size: usize) -> Self
pub fn with_memory_budget(max_size: usize, budget_bytes: usize) -> Self
Sourcepub fn insert(&mut self, coord: ChunkCoord, chunk: TerrainChunk)
pub fn insert(&mut self, coord: ChunkCoord, chunk: TerrainChunk)
Insert or replace a chunk. Evicts LRU if over capacity.
Sourcepub fn get(&mut self, coord: ChunkCoord) -> Option<&TerrainChunk>
pub fn get(&mut self, coord: ChunkCoord) -> Option<&TerrainChunk>
Get a chunk by coord, updating access time.
Sourcepub fn contains(&self, coord: ChunkCoord) -> bool
pub fn contains(&self, coord: ChunkCoord) -> bool
Check whether the cache contains a coord without updating LRU.
Sourcepub fn remove(&mut self, coord: ChunkCoord) -> Option<TerrainChunk>
pub fn remove(&mut self, coord: ChunkCoord) -> Option<TerrainChunk>
Remove a specific coord from the cache.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn current_memory_bytes(&self) -> usize
Auto Trait Implementations§
impl Freeze for ChunkCache
impl RefUnwindSafe for ChunkCache
impl Send for ChunkCache
impl Sync for ChunkCache
impl Unpin for ChunkCache
impl UnsafeUnpin for ChunkCache
impl UnwindSafe for ChunkCache
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.