#[non_exhaustive]
pub enum TypeAst<'a> { Some, Any, Dyn(TypeConstraintsAst<'a>), Ident, Param, Function(Box<FunctionAst<'a>>), FunctionWithConstraints { constraints: Spanned<'a, ConstraintsAst<'a>>, function: Box<Spanned<'a, FunctionAst<'a>>>, }, Tuple(TupleAst<'a>), Slice(SliceAst<'a>), Object(ObjectAst<'a>), }
Expand description

Type annotation after parsing.

Compared to Type, this enum corresponds to AST, not to the logical presentation of a type.

Examples

use arithmetic_parser::InputSpan;

let input = InputSpan::new("(Num, ('T) -> ('T, 'T))");
let (_, ty) = TypeAst::parse(input)?;
let TypeAst::Tuple(elements) = ty.extra else {
    unreachable!();
};
assert_eq!(elements.start[0].extra, TypeAst::Ident);
assert_matches!(
    &elements.start[1].extra,
    TypeAst::Function { .. }
);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Some

Type placeholder (_). Corresponds to a certain type that is not specified, like _ in type annotations in Rust.

§

Any

Any type (any).

§

Dyn(TypeConstraintsAst<'a>)

Dynamically applied constraints (dyn _).

§

Ident

Non-ticked identifier, e.g., Bool.

§

Param

Ticked identifier, e.g., 'T.

§

Function(Box<FunctionAst<'a>>)

Functional type.

§

FunctionWithConstraints

Fields

§constraints: Spanned<'a, ConstraintsAst<'a>>

Constraints on function params.

§function: Box<Spanned<'a, FunctionAst<'a>>>

Function body.

Functional type with constraints.

§

Tuple(TupleAst<'a>)

Tuple type; for example, (Num, Bool).

§

Slice(SliceAst<'a>)

Slice type; for example, [Num] or [(Num, T); N].

§

Object(ObjectAst<'a>)

Object type; for example, { len: Num }. Not to be confused with object constraints.

Implementations§

source§

impl<'a> TypeAst<'a>

source

pub fn try_from(def: &'a str) -> Result<SpannedTypeAst<'a>, ParseError>

Parses type AST from a string.

source§

impl<'a> TypeAst<'a>

source

pub fn parse(input: InputSpan<'a>) -> NomResult<'a, Spanned<'a, Self>>

Parses input as a type. This parser can be composed using nom infrastructure.

Trait Implementations§

source§

impl<'a> Clone for TypeAst<'a>

source§

fn clone(&self) -> TypeAst<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for TypeAst<'a>

source§

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

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

impl<'a> PartialEq<TypeAst<'a>> for TypeAst<'a>

source§

fn eq(&self, other: &TypeAst<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for TypeAst<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for TypeAst<'a>

§

impl<'a> Send for TypeAst<'a>

§

impl<'a> Sync for TypeAst<'a>

§

impl<'a> Unpin for TypeAst<'a>

§

impl<'a> UnwindSafe for TypeAst<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.