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