Skip to main content

Math

Struct Math 

Source
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: Node

Implementations§

Source§

impl Math

Source

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.

Source

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).

Source

pub fn is_math_function(name: &str) -> bool

Whether name is a math function’s name.

Source

pub fn fits(&self, expect: Expect) -> bool

Whether the function’s type is what expect asks for.

Source

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).

Source

pub fn substitute_keywords(&self, f: &impl Fn(&str) -> Option<f64>) -> Math

The function with its keywords (a relative colour’s channel names) replaced by the numbers f gives, then simplified again.

Source

pub fn leaf(&self) -> Option<Leaf>

The value, if simplifying left a single one.

Trait Implementations§

Source§

impl Clone for Math

Source§

fn clone(&self) -> Math

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Math

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Math

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Math

Source§

fn eq(&self, other: &Math) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.