pub trait CalcNodeLeaf:
Clone
+ Sized
+ PartialEq
+ ToCss {
Show 20 methods
// Required methods
fn unit(&self) -> CalcUnits;
fn unitless_value(&self) -> Option<f32>;
fn compare(
&self,
other: &Self,
base_is_positive: PositivePercentageBasis,
) -> Option<Ordering>;
fn new_number(value: f32) -> Self;
fn as_number(&self) -> Option<f32>;
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);
fn sort_key(&self) -> SortKey;
// Provided methods
fn is_same_unit_as(&self, other: &Self) -> bool { ... }
fn gt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool { ... }
fn lt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool { ... }
fn lte(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool { ... }
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, ()> { ... }
}
Expand description
A trait that represents all the stuff a valid leaf of a calc expression.
Required Methods§
Sourcefn unitless_value(&self) -> Option<f32>
fn unitless_value(&self) -> Option<f32>
Returns the unitless value of this leaf if one is available.
Sourcefn compare(
&self,
other: &Self,
base_is_positive: PositivePercentageBasis,
) -> Option<Ordering>
fn compare( &self, other: &Self, base_is_positive: PositivePercentageBasis, ) -> Option<Ordering>
Do a partial comparison of these values.
Sourcefn new_number(value: f32) -> Self
fn new_number(value: f32) -> Self
Create a new leaf with a number value.
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.
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 gt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
fn gt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
Return whether a leaf is greater than another.
Sourcefn lt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
fn lt(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
Return whether a leaf is less than another.
Sourcefn lte(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
fn lte(&self, other: &Self, basis_positive: PositivePercentageBasis) -> bool
Return whether a leaf is smaller or equal than another.
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.