这个宏让你的struct的字段变为
pub
,省去在每个字段名前加pub
的操作;注意 仅仅作用于字段上,对struct的可见性没有影响
This macro add
pub
before your structs' fields; Notice: It won't addpub
before your structs
```rust use pubthis::pubthis;
struct Father
mod children{ use pubthis::pubthis; #[pub_this] pub struct Son { name: String, age: usize, }
pub struct Daughter {
name: String,
age: usize,
}
}
fn main() { let f1 = Father { name: "me".tostring(), age: 55, child: children::Son { name: "You".tostring(), age: 10, }, }; let f2 = Father { name: "me".tostring(), age: 55, child: children::Daughter { name: "You".tostring(), // hint private field age: 10, // hint private field }, }; println!{"{}",f1.child.name} }
```
Here is what it looks like after expand