pub trait CalcNodeLeaf:
Clone
+ Sized
+ PartialEq
+ ToCss
+ ToTyped
+ Debug {
Show 27 methods
// Required methods
fn numeric_type(&self) -> NumericType;
fn unitless_value(&self) -> Option<f32>;
fn as_percentage(&self) -> Option<(f32, Optional<NumericBaseType>)>;
fn canonical_value(&self) -> Option<f32>;
fn as_angle_radians(&self) -> Option<f32>;
fn new_angle_from_radians(radians: f32) -> Self;
fn compare(&self, other: &Self) -> Option<Ordering>;
fn new_number(value: f32) -> Self;
fn as_number(&self) -> Option<f32>;
fn new_from_typed_value(
value: f32,
numeric_type: NumericType,
) -> Result<Self, ()>;
fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()>;
fn try_product_in_place(&mut self, other: &mut Self) -> bool;
fn try_op<O>(&self, other: &Self, op: O) -> Result<Self, ()>
where O: Fn(f32, f32) -> f32;
fn map(&mut self, op: impl FnMut(f32) -> f32) -> Result<(), ()>;
fn simplify(&mut self) -> SimplificationResult;
fn sort_key(&self) -> SortKey;
// Provided methods
fn is_same_unit_as(&self, other: &Self) -> bool { ... }
fn gt(&self, other: &Self) -> bool { ... }
fn lt(&self, other: &Self) -> bool { ... }
fn lte(&self, other: &Self) -> bool { ... }
fn as_number_or_angle_radians(&self) -> Option<f32> { ... }
fn is_negative(&self) -> Result<bool, ()> { ... }
fn is_infinite(&self) -> Result<bool, ()> { ... }
fn is_zero(&self) -> Result<bool, ()> { ... }
fn is_nan(&self) -> Result<bool, ()> { ... }
fn sign_from(leaf: &impl CalcNodeLeaf) -> Result<Self, ()> { ... }
fn should_serialize_with_root_calc_wrapper(&self) -> bool { ... }
}Expand description
A trait that represents all the stuff a valid leaf of a calc expression.
Required Methods§
Sourcefn numeric_type(&self) -> NumericType
fn numeric_type(&self) -> NumericType
Returns the type of the leaf.
Sourcefn unitless_value(&self) -> Option<f32>
fn unitless_value(&self) -> Option<f32>
Returns the unitless value of this leaf if one is available.
Sourcefn 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.
Sourcefn 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
Sourcefn 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.
Sourcefn 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.
Sourcefn new_number(value: f32) -> Self
fn new_number(value: f32) -> Self
Create a new leaf with a number value.
Sourcefn 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.
Sourcefn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()>
fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()>
Tries to merge one leaf into another using the sum, that is, perform x + y.
Sourcefn 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.
Sourcefn 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.
Sourcefn 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.
Sourcefn simplify(&mut self) -> SimplificationResult
fn simplify(&mut self) -> SimplificationResult
Canonicalizes the expression if necessary.
Provided Methods§
Sourcefn 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)
Sourcefn 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.
Sourcefn is_negative(&self) -> Result<bool, ()>
fn is_negative(&self) -> Result<bool, ()>
Whether this value is known-negative.
Sourcefn is_infinite(&self) -> Result<bool, ()>
fn is_infinite(&self) -> Result<bool, ()>
Whether this value is infinite.
Sourcefn sign_from(leaf: &impl CalcNodeLeaf) -> Result<Self, ()>
fn sign_from(leaf: &impl CalcNodeLeaf) -> Result<Self, ()>
Create a new leaf containing the sign() result of the given leaf.
Sourcefn 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".