1use crate::ast::prelude::*;
23#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6 rt::<ast::Type>("Bar");
7 rt::<ast::Type>("one::two::three::four::Five");
8 rt::<ast::Type>("Self");
9 rt::<ast::Type>("(one::One, two::Two)");
10 rt::<ast::Type>("(one::One, (two::Two, three::Three))");
11}
1213/// A type, used for static typing.
14#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Spanned)]
15#[non_exhaustive]
16pub enum Type {
17/// If the type is an identifier or a path.
18Path(ast::Path),
19/// If the type should return nothing (a.k.a the "never" type in Rust).
20Bang(T![!]),
21/// If the type is a tuple.
22Tuple(ast::Parenthesized<Box<Type>, T![,]>),
23}
2425impl Parse for Type {
26fn parse(p: &mut Parser<'_>) -> Result<Self> {
27let segment = match p.nth(0)? {
28K![!] => Self::Bang(p.parse()?),
29K!['('] => Self::Tuple(p.parse()?),
30_ => Self::Path(p.parse()?),
31 };
3233Ok(segment)
34 }
35}