pub type CalcNode = GenericCalcNode<Leaf>;Expand description
A calc node representation for specified values.
Aliased Type§
#[repr(u8)]pub enum CalcNode {
Show 14 variants
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>>),
Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>>>),
AnchorSize(Box<GenericAnchorSizeFunction<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: RoundingStrategyThe 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.
Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>>>)
An anchor() function.
AnchorSize(Box<GenericAnchorSizeFunction<Box<GenericCalcNode<Leaf>>>>)
An anchor-size() function.
Implementations§
Source§impl CalcNode
impl CalcNode
Sourcefn parse_one<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
allowed: AllowParse,
) -> Result<Self, ParseError<'i>>
fn parse_one<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> 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: AllowParse,
) -> Result<Self, ParseError<'i>>
pub fn parse<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, allowed: AllowParse, ) -> 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: AllowParse, ) -> Result<Self, ParseError<'i>>
Sourcefn parse_product<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
allowed: AllowParse,
) -> Result<Self, ParseError<'i>>
fn parse_product<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> 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:
22 * 22 * 2 + 2(but will leave the+ 2unparsed).
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_length_or_percentage<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType,
function: MathFunction,
allow_anchor: AllowAnchorPositioningFunctions,
) -> Result<CalcLengthPercentage, ParseError<'i>>
pub fn parse_length_or_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, allow_anchor: AllowAnchorPositioningFunctions, ) -> Result<CalcLengthPercentage, ParseError<'i>>
Convenience parsing function for <length> | <percentage>, and, optionally, anchor().
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>.