Skip to main content

LayoutCache

Struct LayoutCache 

Source
pub struct LayoutCache { /* private fields */ }
Expand description

A memoizing cache of computed layout rectangles.

Implementations§

Source§

impl LayoutCache

Source

pub fn new() -> Self

Create an empty cache.

Source

pub fn len(&self) -> usize

Number of stored entries.

Source

pub fn is_empty(&self) -> bool

Whether the cache holds no entries.

Source

pub fn hits(&self) -> u64

Cache hit count since creation (or last reset_stats).

Source

pub fn misses(&self) -> u64

Cache miss count since creation (or last reset_stats).

Source

pub fn hit_rate(&self) -> f32

Hit rate in [0, 1]; 0 when there have been no accesses.

Source

pub fn reset_stats(&mut self)

Reset the hit/miss counters (leaves entries intact).

Source

pub fn get( &mut self, id: WidgetId, avail: Size, content_hash: u64, ) -> Option<Rect>

Look up the cached rect for (id, avail, content_hash).

Returns None (a miss) when there is no matching entry or when id is currently marked dirty. Updates the hit/miss counters.

Source

pub fn put(&mut self, id: WidgetId, avail: Size, content_hash: u64, rect: Rect)

Store the computed rect for (id, avail, content_hash), clearing any dirty flag on id (it is now freshly computed).

Source

pub fn invalidate(&mut self, id: WidgetId)

Mark id dirty so its next get misses regardless of key. The stale entries are dropped immediately to bound memory.

Source

pub fn invalidate_many(&mut self, ids: impl IntoIterator<Item = WidgetId>)

Mark several nodes dirty at once (e.g. an invalidated subtree).

Source

pub fn is_dirty(&self, id: WidgetId) -> bool

Whether id is currently flagged dirty.

Source

pub fn clear(&mut self)

Drop every entry and dirty flag (a full layout invalidation).

Trait Implementations§

Source§

impl Debug for LayoutCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LayoutCache

Source§

fn default() -> LayoutCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.