compose_syntax/ast/
path_access.rs

1use crate::ast::macros::node;
2use crate::ast::{Expr, Ident};
3
4node! {
5    struct PathAccess
6}
7
8impl<'a> PathAccess<'a> {
9    pub fn target(self) -> Expr<'a> {
10        self.0.cast_first()
11    }
12    
13    pub fn member(self) -> Ident<'a> {
14        self.0.cast_last()
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::assert_ast;
22
23    #[test]
24    fn test_path_access() {
25        assert_ast! {
26            "foo::bar",
27            path as PathAccess {
28                with target: Ident = path.target() => {
29                    assert_eq!(target.get(), "foo");
30                }
31                with member: Ident = path.member() => {
32                    assert_eq!(member.get(), "bar");
33                }
34            }
35        }
36    }
37}