ink_analyzer_ir/
storage_item.rs1use ra_ap_syntax::ast;
4
5#[ink_analyzer_macro::entity(macro_kind = StorageItem)]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct StorageItem {
9 ast: ast::Adt,
11}
12
13impl StorageItem {
14 impl_pub_ast_type_getter!(adt, Adt);
15
16 impl_pub_ink_arg_getter!(packed_arg, Packed, packed);
17
18 impl_pub_ink_arg_getter!(derive_arg, Derive, derive);
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24 use crate::test_utils::*;
25 use crate::traits::InkEntity;
26 use quote::quote;
27 use test_utils::quote_as_str;
28
29 #[test]
30 fn cast_works() {
31 for code in [
32 quote! {
33 struct MyStorageItem {
34 }
35 },
36 quote! {
37 enum MyStorageItem {
38 }
39 },
40 quote! {
41 union MyStorageItem {
42 }
43 },
44 ] {
45 let node = parse_first_syntax_node(quote_as_str! {
46 #[ink::storage_item(packed, derive=false)]
47 #code
48 });
49
50 let storage_item = StorageItem::cast(node).unwrap();
51
52 assert!(storage_item.packed_arg().is_some());
54
55 assert!(storage_item.derive_arg().is_some());
57
58 assert!(storage_item.adt().is_some());
60 }
61 }
62}