ink_analyzer_ir/
topic.rs

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
//! ink! topic IR.

use ra_ap_syntax::ast;

/// An ink! topic.
#[ink_analyzer_macro::entity(arg_kind = Topic)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Topic {
    // ASTNode type.
    ast: ast::RecordField,
}

impl Topic {
    impl_pub_ast_type_getter!(field, RecordField);
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::test_utils::*;
    use crate::traits::InkEntity;
    use ra_ap_syntax::AstNode;
    use test_utils::quote_as_str;

    #[test]
    fn cast_works() {
        let node: ast::RecordField = parse_first_ast_node_of_type(quote_as_str! {
            pub struct MyEvent {
                #[ink(topic)]
                value: i32,
            }
        });

        let topic = Topic::cast(node.syntax().clone()).unwrap();

        // `field` item exists.
        assert!(topic.field().is_some());
    }
}