1 #[macro_use] 2 extern crate derive_builder; 3 4 /// This builder is in an inner module to make sure private fields aren't accessible 5 /// from the `main` function. 6 mod inner { 7 /// The `LoremBuilder` struct will have private fields for `ipsum` and `dolor`, and 8 /// a public `sit` field. 9 #[derive(Debug, Builder)] 10 #[builder(field(private), setter(into))] 11 pub struct Lorem { 12 ipsum: String, 13 dolor: u16, 14 #[builder(field(public))] 15 sit: bool, 16 } 17 } 18 main()19fn main() { 20 use inner::LoremBuilder; 21 22 let mut lorem = LoremBuilder::default(); 23 lorem.dolor(15u16); 24 lorem.sit = Some(true); // <-- public 25 lorem.dolor = Some(0); // <-- private 26 //~^ ERROR field `dolor` of struct `inner::LoremBuilder` is private 27 }