Struct taffy::tree::cache::Cache

source ·
pub struct Cache {
    final_layout_entry: Option<CacheEntry<LayoutOutput>>,
    measure_entries: [Option<CacheEntry<Size<f32>>>; 9],
}
Expand description

A cache for caching the results of a sizing a Grid Item or Flexbox Item

Fields§

§final_layout_entry: Option<CacheEntry<LayoutOutput>>

The cache entry for the node’s final layout

§measure_entries: [Option<CacheEntry<Size<f32>>>; 9]

The cache entries for the node’s preliminary size measurements

Implementations§

source§

impl Cache

source

pub const fn new() -> Self

Create a new empty cache

source

fn compute_cache_slot( known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, ) -> usize

Return the cache slot to cache the current computed result in

§Caching Strategy

We need multiple cache slots, because a node’s size is often queried by it’s parent multiple times in the course of the layout process, and we don’t want later results to clobber earlier ones.

The two variables that we care about when determining cache slot are:

  • How many “known_dimensions” are set. In the worst case, a node may be called first with neither dimension known, then with one dimension known (either width of height - which doesn’t matter for our purposes here), and then with both dimensions known.
  • Whether unknown dimensions are being sized under a min-content or a max-content available space constraint (definite available space shares a cache slot with max-content because a node will generally be sized under one or the other but not both).
§Cache slots:
  • Slot 0: Both known_dimensions were set
  • Slots 1-4: 1 of 2 known_dimensions were set and:
    • Slot 1: width but not height known_dimension was set and the other dimension was either a MaxContent or Definite available space constraintraint
    • Slot 2: width but not height known_dimension was set and the other dimension was a MinContent constraint
    • Slot 3: height but not width known_dimension was set and the other dimension was either a MaxContent or Definite available space constraintable space constraint
    • Slot 4: height but not width known_dimension was set and the other dimension was a MinContent constraint
  • Slots 5-8: Neither known_dimensions were set and:
    • Slot 5: x-axis available space is MaxContent or Definite and y-axis available space is MaxContent or Definite
    • Slot 6: x-axis available space is MaxContent or Definite and y-axis available space is MinContent
    • Slot 7: x-axis available space is MinContent and y-axis available space is MaxContent or Definite
    • Slot 8: x-axis available space is MinContent and y-axis available space is MinContent
source

pub fn get( &self, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, ) -> Option<LayoutOutput>

Try to retrieve a cached result from the cache

source

pub fn store( &mut self, known_dimensions: Size<Option<f32>>, available_space: Size<AvailableSpace>, run_mode: RunMode, layout_output: LayoutOutput, )

Store a computed size in the cache

source

pub fn clear(&mut self)

Clear all cache entries

source

pub fn is_empty(&self) -> bool

Returns true if all cache entries are None, else false

Trait Implementations§

source§

impl Clone for Cache

source§

fn clone(&self) -> Cache

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Cache

source§

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

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

impl Default for Cache

source§

fn default() -> Self

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

impl PartialEq for Cache

source§

fn eq(&self, other: &Cache) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Cache

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Cache

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.