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:
- Min-content measurement: width = MinContent (effectively 0)
- Max-content measurement: width = MaxContent (effectively infinite)
- 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: AvailableSpaceThe available width constraint used to compute this layout. This is the key for cache validity checking.
has_floats: boolWhether 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
impl CachedInlineLayout
Sourcepub fn new(
layout: Arc<UnifiedLayout>,
available_width: AvailableSpace,
has_floats: bool,
) -> Self
pub fn new( layout: Arc<UnifiedLayout>, available_width: AvailableSpace, has_floats: bool, ) -> Self
Creates a new cached inline layout.
Sourcepub fn new_with_constraints(
layout: Arc<UnifiedLayout>,
available_width: AvailableSpace,
has_floats: bool,
constraints: UnifiedConstraints,
) -> Self
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.
Sourcepub fn is_valid_for(
&self,
new_width: AvailableSpace,
new_has_floats: bool,
) -> bool
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:
- The available width matches (definite widths must be equal, or both are the same indefinite type)
- 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.
Sourcepub fn should_replace_with(
&self,
new_width: AvailableSpace,
new_has_floats: bool,
) -> bool
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.
Sourcepub fn get_layout(&self) -> &Arc<UnifiedLayout>
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.
Sourcepub fn clone_layout(&self) -> Arc<UnifiedLayout>
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
impl Clone for CachedInlineLayout
Source§fn clone(&self) -> CachedInlineLayout
fn clone(&self) -> CachedInlineLayout
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CachedInlineLayout
impl RefUnwindSafe for CachedInlineLayout
impl Send for CachedInlineLayout
impl Sync for CachedInlineLayout
impl Unpin for CachedInlineLayout
impl UnwindSafe for CachedInlineLayout
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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