pub struct Math {
pub root: Node,
}Expand description
A math function’s value: its simplified calculation tree.
use parsec_css::values::Math;
let values = parsec_css::parse_component_values("calc(1in + 2px - 10% * 2)");
let parsec_css::ComponentValue::Function(f) = &values[0] else { unreachable!() };
assert_eq!(Math::parse(f).unwrap().to_string(), "calc(-20% + 98px)");Fields§
§root: NodeImplementations§
Source§impl Math
impl Math
Sourcepub fn parse(function: &Function<'_>) -> Option<Math>
pub fn parse(function: &Function<'_>) -> Option<Math>
Parses a math function, or None if it isn’t one or doesn’t parse.
Whether its type suits where it’s used is Math::fits.
Sourcepub fn parse_with(
function: &Function<'_>,
keywords: &[&'static str],
) -> Option<Math>
pub fn parse_with( function: &Function<'_>, keywords: &[&'static str], ) -> Option<Math>
Parses a math function in which keywords stand for numbers, as a
relative color’s channel names do: calc(r * 0.5).
Sourcepub fn is_math_function(name: &str) -> bool
pub fn is_math_function(name: &str) -> bool
Whether name is a math function’s name.
Sourcepub fn fits(&self, expect: Expect) -> bool
pub fn fits(&self, expect: Expect) -> bool
Whether the function’s type is what expect asks for.
Sourcepub fn map_leaves(&self, f: &impl Fn(Leaf) -> Leaf) -> Math
pub fn map_leaves(&self, f: &impl Fn(Leaf) -> Leaf) -> Math
The function with each leaf replaced by what f makes of it, then
simplified again: how a computed value turns 1em into pixels and
lets calc(1em + 2px) become calc(18px).
Trait Implementations§
impl StructuralPartialEq for Math
Auto Trait Implementations§
impl Forget for Math
impl Freeze for Math
impl Move for Math
impl RefUnwindSafe for Math
impl Send for Math
impl Sync for Math
impl Unpin for Math
impl UnsafeUnpin for Math
impl UnwindSafe for Math
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