use crate::ast::prelude::*;
#[test]
#[cfg(not(miri))]
fn ast_parse() {
rt::<ast::ItemStruct>("struct Foo");
rt::<ast::ItemStruct>("struct Foo ( a, b, c )");
rt::<ast::ItemStruct>("struct Foo { a, b, c }");
rt::<ast::ItemStruct>("struct Foo { #[default_value = 1] a, b, c }");
rt::<ast::ItemStruct>("#[alpha] struct Foo ( #[default_value = \"x\" ] a, b, c )");
rt::<ast::Fields>("");
rt::<ast::Fields>("{ a, b, c }");
rt::<ast::Fields>("{ #[x] a, #[y] b, #[z] #[w] #[f32] c }");
rt::<ast::Fields>("{ a, #[attribute] b, c }");
rt::<ast::Fields>("( a, b, c )");
rt::<ast::Fields>("( #[x] a, b, c )");
rt::<ast::Fields>("( #[x] pub a, b, c )");
rt::<ast::Fields>("( a, b, c )");
rt::<ast::Fields>("()");
rt::<ast::Field>("a");
rt::<ast::Field>("#[x] a");
}
#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
#[rune(parse = "meta_only")]
#[non_exhaustive]
pub struct ItemStruct {
#[rune(iter, meta)]
pub attributes: Vec<ast::Attribute>,
#[rune(option, meta)]
pub visibility: ast::Visibility,
pub struct_token: T![struct],
pub ident: ast::Ident,
#[rune(iter)]
pub body: ast::Fields,
#[rune(skip)]
pub(crate) id: ItemId,
}
impl ItemStruct {
pub(crate) fn needs_semi_colon(&self) -> bool {
self.body.needs_semi_colon()
}
}
item_parse!(Struct, ItemStruct, "struct item");
#[derive(Debug, TryClone, PartialEq, Eq, ToTokens, Parse, Spanned)]
#[non_exhaustive]
pub struct Field {
#[rune(iter)]
pub attributes: Vec<ast::Attribute>,
#[rune(option)]
pub visibility: ast::Visibility,
pub name: ast::Ident,
}