Skip to main content

CachedInlineLayout

Struct CachedInlineLayout 

Source
pub struct CachedInlineLayout {
    pub layout: Arc<UnifiedLayout>,
    pub available_width: AvailableSpace,
    pub has_floats: bool,
    pub constraints: Option<UnifiedConstraints>,
}
Expand description

Cached inline layout result with the constraints used to compute it.

This structure solves a fundamental architectural problem: inline layouts (text wrapping, inline-block positioning) depend on the available width. Different layout phases may compute the layout with different widths:

  1. Min-content measurement: width = MinContent (effectively 0)
  2. Max-content measurement: width = MaxContent (effectively infinite)
  3. Final layout: width = Definite(actual_column_width)

Without tracking which constraints were used, a cached result from phase 1 would incorrectly be reused in phase 3, causing text to wrap at the wrong positions (the root cause of table cell width bugs).

By storing the constraints alongside the result, we can:

  • Invalidate the cache when constraints change
  • Keep multiple cached results for different constraint types if needed
  • Ensure the final render always uses a layout computed with correct widths

Fields§

§layout: Arc<UnifiedLayout>

The computed inline layout

§available_width: AvailableSpace

The available width constraint used to compute this layout. This is the key for cache validity checking.

§has_floats: bool

Whether this layout was computed with float exclusions. Float-aware layouts should not be overwritten by non-float layouts.

§constraints: Option<UnifiedConstraints>

The full constraints used to compute this layout. Used for quick relayout after text edits without rebuilding from CSS.

Implementations§

Source§

impl CachedInlineLayout

Source

pub fn new( layout: Arc<UnifiedLayout>, available_width: AvailableSpace, has_floats: bool, ) -> Self

Creates a new cached inline layout.

Source

pub fn new_with_constraints( layout: Arc<UnifiedLayout>, available_width: AvailableSpace, has_floats: bool, constraints: UnifiedConstraints, ) -> Self

Creates a new cached inline layout with full constraints.

Source

pub fn is_valid_for( &self, new_width: AvailableSpace, new_has_floats: bool, ) -> bool

Checks if this cached layout is valid for the given constraints.

A cached layout is valid if:

  1. The available width matches (definite widths must be equal, or both are the same indefinite type)
  2. OR the new request doesn’t have floats but the cached one does (keep float-aware layout)

The second condition preserves float-aware layouts, which are more “correct” than non-float layouts and shouldn’t be overwritten.

Source

pub fn should_replace_with( &self, new_width: AvailableSpace, new_has_floats: bool, ) -> bool

Determines if this cached layout should be replaced by a new layout.

Returns true if the new layout should replace this one.

Source

pub fn get_layout(&self) -> &Arc<UnifiedLayout>

Returns a reference to the inner UnifiedLayout.

This is a convenience method for code that only needs the layout data and doesn’t care about the caching metadata.

Source

pub fn clone_layout(&self) -> Arc<UnifiedLayout>

Returns a clone of the inner Arc.

This is useful for APIs that need to return an owned reference to the layout without exposing the caching metadata.

Trait Implementations§

Source§

impl Clone for CachedInlineLayout

Source§

fn clone(&self) -> CachedInlineLayout

Returns a duplicate 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 CachedInlineLayout

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool