pub struct NumericType { /* private fields */ }Expand description
https://drafts.css-houdini.org/css-typed-om-1/#numeric-typing
The spec models the per-base-type exponents as an ordered map keyed by base
type. We use a fixed-size array indexed by NumericBaseType instead. A
missing entry in the spec’s map and a zero entry are observably equivalent
for every operation the spec defines (comparisons and iteration only
consider non-zero entries), so the array representation is simpler, avoids
allocations, and produces the same results.
non_zero_count and non_zero_except_percent_count are derived fields
maintained in sync with exponents, allowing O(1) type compatibility
checks. They fit without padding into the 2 bytes following percent_hint,
so the struct remains 32 bytes.
Implementations§
Source§impl NumericType
impl NumericType
Sourcepub fn resolution() -> Self
pub fn resolution() -> Self
A numeric type whose resolution exponent is 1.
Sourcepub fn try_from_unit(unit: &str) -> Result<Self, ()>
pub fn try_from_unit(unit: &str) -> Result<Self, ()>
Sourcepub fn from_unit_unchecked(unit: &str) -> Self
pub fn from_unit_unchecked(unit: &str) -> Self
Creates a numeric type from a previously validated unit string.
Sourcepub fn add_types<'a, I>(types: I) -> Result<Self, ()>where
I: Iterator<Item = &'a NumericType>,
pub fn add_types<'a, I>(types: I) -> Result<Self, ()>where
I: Iterator<Item = &'a NumericType>,
Applies the add two types algorithm repeatedly across a sequence of numeric types, returning the combined type.
Sourcepub fn multiply_types<'a, I>(types: I) -> Result<Self, ()>where
I: Iterator<Item = &'a NumericType>,
pub fn multiply_types<'a, I>(types: I) -> Result<Self, ()>where
I: Iterator<Item = &'a NumericType>,
Applies the multiply two types algorithm repeatedly across a sequence of numeric types, returning the combined type.
Trait Implementations§
Source§impl Clone for NumericType
impl Clone for NumericType
Source§fn clone(&self) -> NumericType
fn clone(&self) -> NumericType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NumericType
impl RefUnwindSafe for NumericType
impl Send for NumericType
impl Sync for NumericType
impl Unpin for NumericType
impl UnsafeUnpin for NumericType
impl UnwindSafe for NumericType
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,
impl<T> ErasedDestructor for Twhere
T: 'static,
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