Builder pattern
non-consuming builder
pub struct Command {
inner: imp::Command,
}
impl Command {
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
Command { inner: imp::Command::new(program.as_ref()) }
}
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
self.inner.arg(arg.as_ref());
self
}
pub fn args<I, S>(&mut self, args: I) -> &mut Command
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,
{
for arg in args {
self.arg(arg.as_ref());
}
}
}
consuming builder
pub struct Builder {
name: Option<String>,
stack_size: Option<usize>,
}
impl Builder {
pub fn new() -> Builder {
Builder { name: None, stack_size: None }
}
pub fn name(mut self, name: String) -> Builder {
self.name = Some(name);
self
}
pub fn stack_size(mut self, size: usize) -> Builder {
self.stack_size = Some(size);
self
}
}