1use crate::ast::prelude::*;
2
3#[test]
4#[cfg(not(miri))]
5fn ast_parse() {
6 rt::<ast::ItemStatic>("static value = #{}");
7 rt::<ast::ItemStatic>("static value");
8}
9
10#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
12#[rune(parse = "meta_only")]
13#[non_exhaustive]
14pub struct ItemStatic {
15 #[rune(iter, meta)]
17 pub attributes: Vec<ast::Attribute>,
18 #[rune(option, meta)]
20 pub visibility: ast::Visibility,
21 #[rune(meta)]
23 pub static_token: T![static],
24 pub name: ast::Ident,
26 #[rune(iter)]
32 pub init: Option<ItemStaticInit>,
33 #[rune(skip)]
35 pub(crate) id: ItemId,
36}
37
38impl ItemStatic {
39 pub(crate) fn descriptive_span(&self) -> Span {
42 self.static_token.span().join(self.name.span())
43 }
44}
45
46#[derive(Debug, TryClone, PartialEq, Eq, Parse, ToTokens, Spanned)]
48#[non_exhaustive]
49pub struct ItemStaticInit {
50 pub eq: T![=],
52 pub expr: ast::Expr,
55}
56
57impl Peek for ItemStaticInit {
58 fn peek(p: &mut Peeker<'_>) -> bool {
59 matches!(p.nth(0), K![=])
60 }
61}
62
63item_parse!(Static, ItemStatic, "static item");