Enum AnyExpr

Source
pub enum AnyExpr {
    Point(Expr<Point>),
    Line(Expr<Line>),
    Number(Expr<Number>),
    Circle(Expr<Circle>),
    PointCollection(Expr<PointCollection>),
    Derived(Expr<Derived>),
    Unknown(Expr<Unknown>),
}
Expand description

A type-erased unrolled expression.

Variants§

§

Point(Expr<Point>)

§

Line(Expr<Line>)

§

Number(Expr<Number>)

§

Circle(Expr<Circle>)

§

PointCollection(Expr<PointCollection>)

§

Derived(Expr<Derived>)

§

Unknown(Expr<Unknown>)

Implementations§

Source§

impl AnyExpr

Source

pub fn get_span_mut(&mut self) -> &mut Span

Clones the expression and sets its own span. This will be treated as a separate expression now.

Source

pub fn get_span(&self) -> Span

Get the expression’s span.

Source

pub fn replace_node(&mut self, with: Option<AnyExprNode>) -> Option<AnyExprNode>

Replace the display node with the given node. Also returns the old node.

Source

pub fn get_node(&self) -> Option<&dyn Node>

Get the node without taking it (reference).

Source

pub fn to_scalar(self) -> Option<Expr<Number>>

Source

pub fn as_point(&self) -> Option<&Expr<Point>>

Source

pub fn get_type(&self) -> Type

Get the expression’s value type.

Source

pub fn convert_to(self, to: Type, context: &CompileContext) -> Self

Convert this expression to the given type.

§Errors

Returns an error if the conversion is invalid.

Source

pub fn can_convert_to(&self, to: Type) -> bool

Check if this expression is convertible to the given type.

Source

pub fn can_convert_to_scalar( &self, unit: Option<ComplexUnit>, ) -> Option<Option<ComplexUnit>>

Check if the expression is convertible to the given type. Note that unit of None is ANY scalar, not UNKNOWN-UNIT scalar here. Returns None if conversion isn’t possible and Some with a unit this value would be converted to. If unit is None and the value is also an unknown-unit scalar, Some(None) is returned.

Source

pub fn can_convert_to_collection(&self, len: usize) -> Option<usize>

Check if the expression is convertible to a point collection of the given length.

Source

pub fn can_convert_to_derived(&self, name: &str) -> bool

Check if the expression is convertible to a derived type with the given name.

Source

pub fn boxed(self, span: Span) -> Self

Box an expression with the given span.

Source

pub fn get_variable_span(&self) -> Span

Get the underlying variable’s defining span.

§Panics

Panics if not a variable.

Source

pub fn make_variable(self, name: String) -> Self

Turn this expression into a variable with the given name.

Source

pub fn as_derived(&self) -> Option<&Expr<Derived>>

Source

pub fn try_into_derived(self) -> Result<Expr<Derived>, Self>

Source

pub fn as_number(&self) -> Option<&Expr<Number>>

Trait Implementations§

Source§

impl CloneWithNode for AnyExpr

Source§

fn clone_with_node(&mut self) -> Self

Clone self and take its node.
Source§

fn clone_without_node(&self) -> Self

Clone self without taking its node.
Source§

impl ConvertFrom<AnyExpr> for Circle

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl ConvertFrom<AnyExpr> for Derived

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl ConvertFrom<AnyExpr> for Line

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl ConvertFrom<AnyExpr> for Number

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl ConvertFrom<AnyExpr> for Point

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl ConvertFrom<AnyExpr> for PointCollection

Source§

fn convert_from(value: AnyExpr, context: &CompileContext) -> Expr<Self>

Convert a value to Self. Read more
Source§

fn can_convert_from(value: &AnyExpr) -> bool

Check if conversion from a value to Self can be made.
Source§

impl Debug for AnyExpr

Source§

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

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

impl Display for AnyExpr

Source§

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

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

impl Dummy for AnyExpr

Source§

fn dummy() -> Self

Create a dummy value pretending to be a valid one.
Source§

fn is_dummy(&self) -> bool

Check if this is a dummy value.
Source§

impl From<Expr<Circle>> for AnyExpr

Source§

fn from(value: Expr<Circle>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<Derived>> for AnyExpr

Source§

fn from(value: Expr<Derived>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<Line>> for AnyExpr

Source§

fn from(value: Expr<Line>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<Number>> for AnyExpr

Source§

fn from(value: Expr<Number>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<Point>> for AnyExpr

Source§

fn from(value: Expr<Point>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<PointCollection>> for AnyExpr

Source§

fn from(value: Expr<PointCollection>) -> Self

Converts to this type from the input type.
Source§

impl From<Expr<Unknown>> for AnyExpr

Source§

fn from(value: Expr<Unknown>) -> Self

Converts to this type from the input type.
Source§

impl<const DST_NUM: i64, const DST_DENOM: i64, const ANG_NUM: i64, const ANG_DENOM: i64> From<NumberUnit<DST_NUM, DST_DENOM, ANG_NUM, ANG_DENOM>> for AnyExpr

Source§

fn from(value: NumberUnit<DST_NUM, DST_DENOM, ANG_NUM, ANG_DENOM>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<Pc<N>> for AnyExpr

Source§

fn from(value: Pc<N>) -> Self

Converts to this type from the input type.
Source§

impl From<SegmentExpr> for AnyExpr

Source§

fn from(value: SegmentExpr) -> Self

Converts to this type from the input type.
Source§

impl From<TransformTypeExpr> for AnyExpr

Source§

fn from(value: TransformTypeExpr) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for AnyExpr

§

impl !RefUnwindSafe for AnyExpr

§

impl !Send for AnyExpr

§

impl !Sync for AnyExpr

§

impl Unpin for AnyExpr

§

impl !UnwindSafe for AnyExpr

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> Convert for T

Source§

fn convert<U>(self, context: &CompileContext) -> Expr<U>
where U: ConvertFrom<T>,

Convert self into a specific type. Read more
Source§

fn can_convert<U>(&self) -> bool
where U: ConvertFrom<T>,

Check if self can be converted into a specific type. 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.