【Rust设计模式之建造者模式】

#[derive(Debug)] struct children { name: String, age: u32, } impl children { pub fn find_generator() -> Generator { Generator::default() } } #[derive(Default)] struct Generator { name: String, age: u32, //... and so on... } impl Generator { pub fn new() -> Generator { Generator { name: String::from("generator"), age: 11, //... and so on... } } pub fn buildchildren(self) -> children { children { name: self.name, age: self.age, //... and so on... } } } fn main() { let child_from_generator = Generator::new().buildchildren(); println!("{:?}", child_from_generator); }
上一篇:Linux 文件与目录管理


下一篇:Isaac Gym学习笔记——概述-介绍