Skip to main content

Length

Enum Length 

Source
#[non_exhaustive]
pub enum Length<const DEFAULT_AUTO: bool = true> {
Show 22 variants Auto, Percentage(f32), Rem(f32), Em(f32), Lh(f32), Rlh(f32), Vh(f32), Vw(f32), CqH(f32), CqW(f32), CqMin(f32), CqMax(f32), VMin(f32), VMax(f32), Cm(f32), Mm(f32), In(f32), Q(f32), Pt(f32), Pc(f32), Px(f32), Calc(CalcFormula),
}
Expand description

Represents a value that can be a specific length, percentage, or automatic.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Auto

Automatic sizing based on content

§

Percentage(f32)

Percentage value relative to parent container (0-100)

§

Rem(f32)

Rem value relative to the root font size

§

Em(f32)

Em value relative to the font size

§

Lh(f32)

Lh value relative to the element’s computed line-height

§

Rlh(f32)

Rlh value relative to the root element’s computed line-height

§

Vh(f32)

Vh value relative to the viewport height (0-100)

§

Vw(f32)

Vw value relative to the viewport width (0-100)

§

CqH(f32)

Cqh value relative to the query container height (0-100)

§

CqW(f32)

Cqw value relative to the query container width (0-100)

§

CqMin(f32)

Cqmin value relative to the query container smaller dimension (0-100)

§

CqMax(f32)

Cqmax value relative to the query container larger dimension (0-100)

§

VMin(f32)

Vmin value relative to the smaller viewport dimension (0-100)

§

VMax(f32)

Vmax value relative to the larger viewport dimension (0-100)

§

Cm(f32)

Centimeter value

§

Mm(f32)

Millimeter value

§

In(f32)

Inch value

§

Q(f32)

Quarter value

§

Pt(f32)

Point value

§

Pc(f32)

Picas value

§

Px(f32)

Specific pixel value

§

Calc(CalcFormula)

calc(…) expression

Implementations§

Source§

impl<const DEFAULT_AUTO: bool> Length<DEFAULT_AUTO>

Source

pub fn from_spacing(units: f32) -> Self

Construct a length from a Tailwind spacing-scale multiplier.

Source§

impl<const DEFAULT_AUTO: bool> Length<DEFAULT_AUTO>

Source

pub const fn zero() -> Self

Returns a zero pixel length unit.

Source

pub fn try_negative(self) -> Option<Self>

Negated value, or None for non-negatable forms like auto.

Source

pub fn negative(self) -> Self

Returns a negative length unit.

Source§

impl<const DEFAULT_AUTO: bool> Length<DEFAULT_AUTO>

Trait Implementations§

Source§

impl<const DEFAULT_AUTO: bool> Clone for Length<DEFAULT_AUTO>

Source§

fn clone(&self) -> Length<DEFAULT_AUTO>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const DEFAULT_AUTO: bool> Copy for Length<DEFAULT_AUTO>

Source§

impl<const DEFAULT_AUTO: bool> Debug for Length<DEFAULT_AUTO>

Source§

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

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

impl<const DEFAULT_AUTO: bool> Default for Length<DEFAULT_AUTO>

Source§

fn default() -> Self

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

impl From<Length> for PositionComponent

Source§

fn from(value: Length) -> Self

Converts to this type from the input type.
Source§

impl From<Length> for FontSize

Source§

fn from(value: Length) -> Self

Converts to this type from the input type.
Source§

impl From<Length> for LineHeight

Source§

fn from(value: Length) -> Self

Converts to this type from the input type.
Source§

impl From<PositionComponent> for Length

Source§

fn from(component: PositionComponent) -> Self

Converts to this type from the input type.
Source§

impl<const DEFAULT_AUTO: bool> From<f32> for Length<DEFAULT_AUTO>

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl<'i, const DEFAULT_AUTO: bool> FromCss<'i> for Length<DEFAULT_AUTO>

Source§

const VALID_TOKENS: &'static [CssToken]

Returns the list of valid CSS tokens for this type.
Source§

fn from_css(input: &mut Parser<'i, '_>) -> ParseResult<'i, Self>

Parses the type from a Parser instance.
Source§

fn from_str(source: &'i str) -> ParseResult<'i, Self>
where Self: Sized,

Helper function to parse the type from a string.
Source§

const EXPECT_MESSAGE: CssExpectedMessage = CssExpectedMessage::OneValue

Message template used when building parse errors for this type.
Source§

impl<const DEFAULT_AUTO: bool> Neg for Length<DEFAULT_AUTO>

Source§

type Output = Length<DEFAULT_AUTO>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const DEFAULT_AUTO: bool> PartialEq for Length<DEFAULT_AUTO>

Source§

fn eq(&self, other: &Length<DEFAULT_AUTO>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const DEFAULT_AUTO: bool> StructuralPartialEq for Length<DEFAULT_AUTO>

Source§

impl<const DEFAULT_AUTO: bool> TailwindPropertyParser for Length<DEFAULT_AUTO>

Source§

fn parse_tw(token: &str) -> Option<Self>

Parse a tailwind property from a token.
Source§

fn parse_tw_with_arbitrary(token: &str) -> Option<Self>

Parse a tailwind property from a token, with support for arbitrary values.
Source§

impl<const DEFAULT_AUTO: bool> ToCss for Length<DEFAULT_AUTO>

Source§

fn to_css<W: Write>(&self, dest: &mut W) -> Result

Write the CSS representation of this value into dest.

Auto Trait Implementations§

§

impl<const DEFAULT_AUTO: bool> Freeze for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> RefUnwindSafe for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> Send for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> Sync for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> Unpin for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> UnsafeUnpin for Length<DEFAULT_AUTO>

§

impl<const DEFAULT_AUTO: bool> UnwindSafe for Length<DEFAULT_AUTO>

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> Brush for T
where T: Clone + PartialEq + Default + Debug,

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> ErasedDestructor for T
where T: 'static,

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.