#[repr(u8)]pub enum Leaf {
Length(NoCalcLength),
Angle(NoCalcAngle),
Time(NoCalcTime),
Resolution(NoCalcResolution),
ColorComponent(ChannelKeyword),
Percentage(CalcPercentageLeaf),
Number(NoCalcNumber),
TreeCountingFunction(TreeCountingFunction),
}Expand description
A leaf node inside a Calc expression’s AST.
Variants§
Length(NoCalcLength)
<length>
Angle(NoCalcAngle)
<angle>
Time(NoCalcTime)
<time>
Resolution(NoCalcResolution)
<resolution>
ColorComponent(ChannelKeyword)
A component of a color.
Percentage(CalcPercentageLeaf)
<percentage>
Number(NoCalcNumber)
<number>
TreeCountingFunction(TreeCountingFunction)
A tree-counting function.
Implementations§
Source§impl Leaf
impl Leaf
Sourcepub fn to_computed_value(
&self,
context: Option<&Context<'_>>,
origin_color: Option<&AbsoluteColor>,
) -> Self
pub fn to_computed_value( &self, context: Option<&Context<'_>>, origin_color: Option<&AbsoluteColor>, ) -> Self
Computes this leaf against the given context (if any), substituting color
channel references with the matching channel of origin_color when it is
provided. If no origin color is available, channel references are kept
symbolic so they can be resolved later.
Trait Implementations§
Source§impl CalcNodeLeaf for Leaf
impl CalcNodeLeaf for Leaf
Source§fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()>
fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()>
Tries to merge one sum to another, that is, perform x + y.
Only handles leaf nodes, it’s the caller’s responsibility to simplify them before calling this if needed.
Source§fn numeric_type(&self) -> NumericType
fn numeric_type(&self) -> NumericType
Returns the type of the leaf.
Source§fn unitless_value(&self) -> Option<f32>
fn unitless_value(&self) -> Option<f32>
Returns the unitless value of this leaf if one is available.
Source§fn canonical_value(&self) -> Option<f32>
fn canonical_value(&self) -> Option<f32>
Returns the canonical value of this leaf in the type’s canonical unit,
if there is enough information to determine its numeric value.
https://drafts.csswg.org/css-values-4/#simplify-a-calculation-tree
Source§fn is_same_unit_as(&self, other: &Self) -> bool
fn is_same_unit_as(&self, other: &Self) -> bool
Return true if the units of both leaves are equal. (NOTE: Does not take
the values into account)
Source§fn as_percentage(&self) -> Option<(f32, Optional<NumericBaseType>)>
fn as_percentage(&self) -> Option<(f32, Optional<NumericBaseType>)>
Returns the value and percent hint if this leaf is a percentage.
Source§fn as_angle_radians(&self) -> Option<f32>
fn as_angle_radians(&self) -> Option<f32>
Returns the angle value in radians if this leaf is an angle.
Source§fn new_angle_from_radians(radians: f32) -> Self
fn new_angle_from_radians(radians: f32) -> Self
Creates a new angle leaf from a value in radians.
Source§fn new_number(value: f32) -> Self
fn new_number(value: f32) -> Self
Create a new leaf with a number value.
Source§fn new_from_typed_value(
value: f32,
numeric_type: NumericType,
) -> Result<Self, ()>
fn new_from_typed_value( value: f32, numeric_type: NumericType, ) -> Result<Self, ()>
Create a new leaf with
value in the canonical unit of the given type.
Returns Err(()) if the type cannot be constructed as a leaf.Source§fn simplify(&mut self) -> SimplificationResult
fn simplify(&mut self) -> SimplificationResult
Canonicalizes the expression if necessary.
Source§fn try_product_in_place(&mut self, other: &mut Self) -> bool
fn try_product_in_place(&mut self, other: &mut Self) -> bool
Try to merge the right leaf into the left by using a multiplication. Return true if the
merge was successful, otherwise false.
Source§fn try_op<O>(&self, other: &Self, op: O) -> Result<Self, ()>
fn try_op<O>(&self, other: &Self, op: O) -> Result<Self, ()>
Tries a generic arithmetic operation.
Source§fn map(&mut self, op: impl FnMut(f32) -> f32) -> Result<(), ()>
fn map(&mut self, op: impl FnMut(f32) -> f32) -> Result<(), ()>
Map the value of this node with the given operation.
Source§fn should_serialize_with_root_calc_wrapper(&self) -> bool
fn should_serialize_with_root_calc_wrapper(&self) -> bool
Whether this leaf node should serialize with a
calc() wrapper
if this node is the root of the calculation tree.Source§fn as_number_or_angle_radians(&self) -> Option<f32>
fn as_number_or_angle_radians(&self) -> Option<f32>
Returns a number or angle radians if the leaf is a number or angle.
Source§impl MallocSizeOf for Leaf
impl MallocSizeOf for Leaf
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Measure the heap usage of all descendant heap-allocated structures, but
not the space taken up by the value itself.
Source§impl ToCss for Leaf
impl ToCss for Leaf
Source§fn to_css<W>(&self, dest: &mut CssWriter<'_, W>) -> Resultwhere
W: Write,
fn to_css<W>(&self, dest: &mut CssWriter<'_, W>) -> Resultwhere
W: Write,
Serialize
self in CSS syntax, writing to dest.Source§fn to_css_string(&self) -> String
fn to_css_string(&self) -> String
Serialize
self in CSS syntax and return a string. Read moreSource§fn to_css_cssstring(&self) -> String
fn to_css_cssstring(&self) -> String
Serialize
self in CSS syntax and return a CssString. Read moreSource§impl ToTyped for Leaf
impl ToTyped for Leaf
Source§fn to_typed_value(&self) -> Option<TypedValue>
fn to_typed_value(&self) -> Option<TypedValue>
Source§fn to_numeric_value(&self) -> Option<NumericValue>
fn to_numeric_value(&self) -> Option<NumericValue>
Source§fn to_typed_value_list(&self) -> Option<TypedValueList>
fn to_typed_value_list(&self) -> Option<TypedValueList>
impl StructuralPartialEq for Leaf
Auto Trait Implementations§
impl Freeze for Leaf
impl RefUnwindSafe for Leaf
impl Send for Leaf
impl Sync for Leaf
impl Unpin for Leaf
impl UnsafeUnpin for Leaf
impl UnwindSafe for Leaf
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
Mutably borrows from an owned value. Read more
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>
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 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>
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 moreSource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
Source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
Source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
Source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert