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.
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
impl CalcNode
sourcefn parse_one<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
allowed_units: CalcUnits,
) -> Result<Self, ParseError<'i>>
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.
sourcepub fn parse<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
allowed_units: CalcUnits,
) -> Result<Self, ParseError<'i>>
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%
.
fn parse_angle_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>
fn parse_number_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>
fn parse_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed_units: CalcUnits, ) -> Result<Self, ParseError<'i>>
sourcefn parse_product<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
allowed_units: CalcUnits,
) -> Result<Self, ParseError<'i>>
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).
fn try_resolve<'i, 't, F>( input: &Parser<'i, 't>, closure: F, ) -> Result<CSSFloat, ParseError<'i>>
sourcepub fn into_length_or_percentage(
self,
clamping_mode: AllowedNumericType,
) -> Result<CalcLengthPercentage, ()>
pub fn into_length_or_percentage( self, clamping_mode: AllowedNumericType, ) -> Result<CalcLengthPercentage, ()>
Tries to simplify this expression into a <length>
or <percentage>
value.
sourcefn to_time(&self, clamping_mode: Option<AllowedNumericType>) -> Result<Time, ()>
fn to_time(&self, clamping_mode: Option<AllowedNumericType>) -> Result<Time, ()>
Tries to simplify this expression into a <time>
value.
sourcefn to_resolution(&self) -> Result<Resolution, ()>
fn to_resolution(&self) -> Result<Resolution, ()>
Tries to simplify the expression into a <resolution>
value.
sourcefn to_number(&self) -> Result<CSSFloat, ()>
fn to_number(&self) -> Result<CSSFloat, ()>
Tries to simplify this expression into a <number>
value.
sourcefn to_percentage(&self) -> Result<CSSFloat, ()>
fn to_percentage(&self) -> Result<CSSFloat, ()>
Tries to simplify this expression into a <percentage>
value.
sourcepub fn math_function<'i>(
_: &ParserContext<'_>,
name: &CowRcStr<'i>,
location: SourceLocation,
) -> Result<MathFunction, ParseError<'i>>
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.
sourcepub fn parse_integer<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<CSSInteger, ParseError<'i>>
pub fn parse_integer<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSInteger, ParseError<'i>>
Convenience parsing function for integers.
sourcepub fn parse_length_or_percentage<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType,
function: MathFunction,
) -> Result<CalcLengthPercentage, ParseError<'i>>
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>
.
sourcepub fn parse_percentage<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<CSSFloat, ParseError<'i>>
pub fn parse_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>
Convenience parsing function for percentages.
sourcepub fn parse_length<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType,
function: MathFunction,
) -> Result<CalcLengthPercentage, ParseError<'i>>
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>
.
sourcepub fn parse_number<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<CSSFloat, ParseError<'i>>
pub fn parse_number<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>
Convenience parsing function for <number>
.
sourcepub fn parse_angle<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<Angle, ParseError<'i>>
pub fn parse_angle<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Angle, ParseError<'i>>
Convenience parsing function for <angle>
.
sourcepub fn parse_time<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType,
function: MathFunction,
) -> Result<Time, ParseError<'i>>
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>
.
sourcepub fn parse_resolution<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<Resolution, ParseError<'i>>
pub fn parse_resolution<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Resolution, ParseError<'i>>
Convenience parsing function for <resolution>
.