#[non_exhaustive]pub enum WidthSpec {
Auto,
Fixed(u32),
Pct(u8),
Ratio(u16, u16),
MinMax {
min: u32,
max: u32,
},
}Expand description
Width specification for a flexbox item.
Replaces the previous trio of Option-typed fields (min_width,
max_width, width_pct) with a single tagged enum. Resolution at
layout time dispatches on the variant.
Constraints::default() produces WidthSpec::Auto.
§Variant semantics
Auto— no width constraint; the element sizes from content and available space.Fixed(n)— exact cell width. Equivalent toMinMax { min: Some(n), max: Some(n) }.Pct(p)— percentage of parent width (clamped to 0..=100).Ratio(num, den)— exact integer fraction. For exampleRatio(1, 3)producesarea / 3. Floor division:area = 80, num = 1, den = 3→26. Adenof0is treated as no constraint.MinMax { min, max }— bounds on each side independently.
§Example
use slt::{Constraints, WidthSpec};
let c = Constraints::default().w_ratio(1, 3);
assert_eq!(c.width, WidthSpec::Ratio(1, 3));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Auto
Unconstrained — sizes from content and available space.
Fixed(u32)
Exact cell width.
Pct(u8)
Percentage of parent width (0..=100).
Ratio(u16, u16)
Exact integer fraction of parent (numerator, denominator).
Ratio(1, 3) produces area / 3. Floor division — for
area = 80, num = 1, den = 3 → 26. A den of 0 is treated as
no constraint.
MinMax
Min and/or max bounds. Sentinels are used so that the variant fits
in 12 bytes (24 bytes total for the two-axis Constraints struct):
min = 0means “no minimum” (equivalent toOption::None); since a min of 0 is the same as no minimum, using0as the sentinel does not lose any expressible state.max = u32::MAXmeans “no maximum” (the naturalinfinity).
Use the Constraints::min_w / Constraints::max_w /
Constraints::w_minmax builders to construct this variant
without thinking about sentinels.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for WidthSpec
impl<'de> Deserialize<'de> for WidthSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for WidthSpec
impl Eq for WidthSpec
impl StructuralPartialEq for WidthSpec
Auto Trait Implementations§
impl Freeze for WidthSpec
impl RefUnwindSafe for WidthSpec
impl Send for WidthSpec
impl Sync for WidthSpec
impl Unpin for WidthSpec
impl UnsafeUnpin for WidthSpec
impl UnwindSafe for WidthSpec
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.