pub_this 0.1.0

Make your structs' fields be pub
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 69.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 275.97 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • lesterhnu/pub_this
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lesterhnu

Description

这个宏让你的struct的字段变为 pub ,省去在每个字段名前加pub的操作;注意 仅仅作用于字段上,对struct的可见性没有影响

This macro add pub before your structs' fields; Notice: It won't add pub before your structs

Example

use pub_this::pub_this;

#[pub_this]
struct Father<T> {
    pub name: String,
    age: usize,
    child: T,
}

mod children{
    use pub_this::pub_this;
    #[pub_this]
    pub struct Son {
        name: String,
        age: usize,
    }

    pub struct Daughter {
        name: String,
        age: usize,
    }
}

fn main() {
    let f1 = Father {
        name: "me".to_string(),
        age: 55,
        child: children::Son {
            name: "You".to_string(),
            age: 10,
        },
    };
    let f2 = Father {
        name: "me".to_string(),
        age: 55,
        child: children::Daughter {
            name: "You".to_string(), // hint private field
            age: 10, // hint private field
        },
    };
    println!{"{}",f1.child.name}
}

Expand

Here is what it looks like after expand

pic