Enum arithmetic_typing::ast::TypeAst
source · #[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
Functional type with constraints.
Fields
§
constraints: Spanned<'a, ConstraintsAst<'a>>
Constraints on function params.
§
function: Box<Spanned<'a, FunctionAst<'a>>>
Function body.
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>
impl<'a> TypeAst<'a>
sourcepub fn try_from(def: &'a str) -> Result<SpannedTypeAst<'a>, ParseError>
pub fn try_from(def: &'a str) -> Result<SpannedTypeAst<'a>, ParseError>
Parses type AST from a string.
Trait Implementations§
source§impl<'a> PartialEq for TypeAst<'a>
impl<'a> PartialEq for TypeAst<'a>
impl<'a> StructuralPartialEq for TypeAst<'a>
Auto Trait Implementations§
impl<'a> Freeze for TypeAst<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)