macro_rules! fake_inheritance { ($sname:ident, $fname:ident, fields = [$($ffname:ident:$return_val:ident;)*]) => { ... }; ($sname:ident, $fname:ident, fields = [$(f($ffname:ident):$return_val:ident;)*]) => { ... }; }
Expand description
Input of this macro follows: (parent_struct_name, field_name_for_inner_struct, fields = [
field_name: field_type; …]) (The … indicates that the pattern can be used infinitely).
For the macro to use the inner struct’s accesor functions (e. g inner.a()
); use
“fields = [f(field_name): field_type; …]”
§Examples
ⓘ
#[macro_use]
extern crate fake_inheritance;
struct Inner {
a: i32, b: i32
}
struct Parent { inner: Inner }
fake_inheritance!(Parent, inner, fields = [a: i32; b: i32;]);
let parent = Parent { inner: Inner { a: 1, b: 2 }};
assert_eq!(parent.a(), 1);
assert_eq!(parent.b(), 2);