// Generate a `build` method to go from builder to original struct. // // This method should require that every one of the fields has been explicitly // set; it should return an error if a field is missing. The precise error type // is not important. Consider using Box, which you can construct // using the impl From for Box. // // impl CommandBuilder { // pub fn build(&mut self) -> Result> { // ... // } // } use builders::Builder; #[derive(Builder)] pub struct Command { executable: String, args: Vec, env: Vec, current_dir: String, } fn main() { let mut builder = Command::builder(); builder.executable("cargo".to_owned()); builder.args(vec!["build".to_owned(), "--release".to_owned()]); builder.env(vec![]); builder.current_dir("..".to_owned()); let command = builder.build().unwrap(); assert_eq!(command.executable, "cargo"); }