Skip to main content

Cache

Struct Cache 

Source
pub struct Cache<T, K: Tiled = Key> { /* private fields */ }
Expand description

Painted tiles, keyed by theme, level, column and row, holding at most cap of cost — bytes of pixels, or a count — the least recently used dropped first. Damage marks the tiles it overlaps stale; a stale tile is still there, and says so, until it is painted again. What a tile holds is the cache’s user’s: pixels in the server, a texture on the GPU.

Implementations§

Source§

impl<T, K: Tiled> Cache<T, K>

Source

pub fn new(cap: usize) -> Cache<T, K>

Source

pub fn get(&mut self, key: &K) -> Option<(&T, bool)>

The tile at key, and whether it is stale; it counts as used.

Source

pub fn peek(&self, key: &K) -> Option<(&T, bool)>

The tile at key and whether it is stale, without counting a use.

Source

pub fn insert(&mut self, key: K, value: T, cost: usize) -> Vec<(K, T)>

Keeps value as the current tile at key, costing cost, and drops the least recently used others until the cache is within its cap. Returns what was dropped.

Source

pub fn remove(&mut self, key: &K) -> Option<T>

Takes the tile at key out.

Source

pub fn damage(&mut self, theme: Theme, origin: (f64, f64), rects: &[KRect])

Marks stale every tile of theme that overlaps one of rects — in the design’s coordinates, the drawing’s top-left at origin — at every level.

Source

pub fn damage_where( &mut self, which: impl Fn(&K) -> bool, origin: (f64, f64), rects: &[KRect], )

Marks stale every tile which picks that overlaps one of rects, as Cache::damage does.

Source

pub fn damage_all(&mut self, theme: Theme)

Marks every tile of theme stale.

Source

pub fn damage_all_where(&mut self, which: impl Fn(&K) -> bool)

Marks every tile which picks stale.

Source

pub fn forget(&mut self, which: impl Fn(&K) -> bool)

Drops every tile which picks.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &T, bool)>

Every tile, with whether it is stale.

Source

pub fn clear(&mut self) -> Vec<T>

Drops every tile.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn cost(&self) -> usize

What the tiles held cost together.

Auto Trait Implementations§

§

impl<T, K> Freeze for Cache<T, K>
where HashMap<K, Entry<T>>: Freeze, BTreeMap<u64, K>: Freeze,

§

impl<T, K> RefUnwindSafe for Cache<T, K>
where HashMap<K, Entry<T>>: RefUnwindSafe, BTreeMap<u64, K>: RefUnwindSafe,

§

impl<T, K> Send for Cache<T, K>
where HashMap<K, Entry<T>>: Send, BTreeMap<u64, K>: Send,

§

impl<T, K> Sync for Cache<T, K>
where HashMap<K, Entry<T>>: Sync, BTreeMap<u64, K>: Sync,

§

impl<T, K> Unpin for Cache<T, K>
where HashMap<K, Entry<T>>: Unpin, BTreeMap<u64, K>: Unpin,

§

impl<T, K> UnsafeUnpin for Cache<T, K>
where HashMap<K, Entry<T>>: UnsafeUnpin, BTreeMap<u64, K>: UnsafeUnpin,

§

impl<T, K> UnwindSafe for Cache<T, K>
where HashMap<K, Entry<T>>: UnwindSafe, BTreeMap<u64, K>: UnwindSafe,

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.