1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use crate::ast; use crate::{Parse, Spanned, ToTokens}; /// A block expression. /// /// # Examples /// /// ```rust /// use rune::{testing, ast}; /// /// let expr = testing::roundtrip::<ast::ExprBlock>("async {}"); /// assert_eq!(expr.block.statements.len(), 0); /// /// let expr = testing::roundtrip::<ast::ExprBlock>("async { 42 }"); /// assert_eq!(expr.block.statements.len(), 1); /// /// let expr = testing::roundtrip::<ast::ExprBlock>("#[retry] async { 42 }"); /// assert_eq!(expr.block.statements.len(), 1); /// assert_eq!(expr.attributes.len(), 1); /// ``` #[derive(Debug, Clone, PartialEq, Eq, Parse, ToTokens, Spanned)] #[rune(parse = "meta_only")] pub struct ExprBlock { /// The attributes for the block. #[rune(iter, meta)] pub attributes: Vec<ast::Attribute>, /// The optional async token. #[rune(iter, meta)] pub async_token: Option<T![async]>, /// The optional const token. #[rune(iter, meta)] pub const_token: Option<T![const]>, /// The optional move token. #[rune(iter, meta)] pub move_token: Option<T![move]>, /// The close brace. pub block: ast::Block, } expr_parse!(Block, ExprBlock, "block expression");