Type Alias style::values::specified::calc::CalcNode

source ·
pub type CalcNode = GenericCalcNode<Leaf>;
Expand description

A calc node representation for specified values.

Aliased Type§

enum CalcNode {
    Leaf(Leaf),
    Negate(Box<GenericCalcNode<Leaf>>),
    Invert(Box<GenericCalcNode<Leaf>>),
    Sum(OwnedSlice<GenericCalcNode<Leaf>>),
    Product(OwnedSlice<GenericCalcNode<Leaf>>),
    MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp),
    Clamp {
        min: Box<GenericCalcNode<Leaf>>,
        center: Box<GenericCalcNode<Leaf>>,
        max: Box<GenericCalcNode<Leaf>>,
    },
    Round {
        strategy: RoundingStrategy,
        value: Box<GenericCalcNode<Leaf>>,
        step: Box<GenericCalcNode<Leaf>>,
    },
    ModRem {
        dividend: Box<GenericCalcNode<Leaf>>,
        divisor: Box<GenericCalcNode<Leaf>>,
        op: ModRemOp,
    },
    Hypot(OwnedSlice<GenericCalcNode<Leaf>>),
    Abs(Box<GenericCalcNode<Leaf>>),
    Sign(Box<GenericCalcNode<Leaf>>),
}

Variants§

§

Leaf(Leaf)

A leaf node.

§

Negate(Box<GenericCalcNode<Leaf>>)

A node that negates its child, e.g. Negate(1) == -1.

§

Invert(Box<GenericCalcNode<Leaf>>)

A node that inverts its child, e.g. Invert(10) == 1 / 10 == 0.1. The child must always resolve to a number unit.

§

Sum(OwnedSlice<GenericCalcNode<Leaf>>)

A sum node, representing a + b + c where a, b, and c are the arguments.

§

Product(OwnedSlice<GenericCalcNode<Leaf>>)

A product node, representing a * b * c where a, b, and c are the arguments.

§

MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp)

A min or max function.

§

Clamp

A clamp() function.

Fields

§min: Box<GenericCalcNode<Leaf>>

The minimum value.

§center: Box<GenericCalcNode<Leaf>>

The central value.

§max: Box<GenericCalcNode<Leaf>>

The maximum value.

§

Round

A round() function.

Fields

§strategy: RoundingStrategy

The rounding strategy.

§value: Box<GenericCalcNode<Leaf>>

The value to round.

§step: Box<GenericCalcNode<Leaf>>

The step value.

§

ModRem

A mod() or rem() function.

Fields

§dividend: Box<GenericCalcNode<Leaf>>

The dividend calculation.

§divisor: Box<GenericCalcNode<Leaf>>

The divisor calculation.

§op: ModRemOp

Is the function mod or rem?

§

Hypot(OwnedSlice<GenericCalcNode<Leaf>>)

A hypot() function

§

Abs(Box<GenericCalcNode<Leaf>>)

An abs() function.

§

Sign(Box<GenericCalcNode<Leaf>>)

A sign() function.

Implementations§

source§

impl CalcNode

source

fn parse_one<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed_units: CalcUnits, ) -> Result<Self, ParseError<'i>>

Tries to parse a single element in the expression, that is, a <length>, <angle>, <time>, <percentage>, <resolution>, etc.

May return a “complex” CalcNode, in the presence of a parenthesized expression, for example.

source

pub fn parse<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, allowed_units: CalcUnits, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, with all nested sub-expressions.

This is in charge of parsing, for example, 2 + 3 * 100%.

source

fn parse_angle_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>

source

fn parse_number_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>

source

fn parse_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed_units: CalcUnits, ) -> Result<Self, ParseError<'i>>

source

fn parse_product<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed_units: CalcUnits, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, and all the products that may follow, and stop as soon as a non-product expression is found.

This should parse correctly:

  • 2
  • 2 * 2
  • 2 * 2 + 2 (but will leave the + 2 unparsed).
source

fn try_resolve<'i, 't, F>( input: &Parser<'i, 't>, closure: F, ) -> Result<CSSFloat, ParseError<'i>>
where F: FnOnce() -> Result<CSSFloat, ()>,

source

pub fn into_length_or_percentage( self, clamping_mode: AllowedNumericType, ) -> Result<CalcLengthPercentage, ()>

Tries to simplify this expression into a <length> or <percentage> value.

source

fn to_time(&self, clamping_mode: Option<AllowedNumericType>) -> Result<Time, ()>

Tries to simplify this expression into a <time> value.

source

fn to_resolution(&self) -> Result<Resolution, ()>

Tries to simplify the expression into a <resolution> value.

source

fn to_angle(&self) -> Result<Angle, ()>

Tries to simplify this expression into an Angle value.

source

fn to_number(&self) -> Result<CSSFloat, ()>

Tries to simplify this expression into a <number> value.

source

fn to_percentage(&self) -> Result<CSSFloat, ()>

Tries to simplify this expression into a <percentage> value.

source

pub fn math_function<'i>( _: &ParserContext<'_>, name: &CowRcStr<'i>, location: SourceLocation, ) -> Result<MathFunction, ParseError<'i>>

Given a function name, and the location from where the token came from, return a mathematical function corresponding to that name or an error.

source

pub fn parse_integer<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSInteger, ParseError<'i>>

Convenience parsing function for integers.

source

pub fn parse_length_or_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length> | <percentage>.

source

pub fn parse_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>

Convenience parsing function for percentages.

source

pub fn parse_length<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length>.

source

pub fn parse_number<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>

Convenience parsing function for <number>.

source

pub fn parse_angle<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Angle, ParseError<'i>>

Convenience parsing function for <angle>.

source

pub fn parse_time<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<Time, ParseError<'i>>

Convenience parsing function for <time>.

source

pub fn parse_resolution<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Resolution, ParseError<'i>>

Convenience parsing function for <resolution>.