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
impl Cache
sourcefn compute_cache_slot(
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
) -> usize
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
sourcepub fn get(
&self,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: RunMode,
) -> Option<LayoutOutput>
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
sourcepub fn store(
&mut self,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: RunMode,
layout_output: LayoutOutput,
)
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
Trait Implementations§
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)