I want to do this, but shorter:
pub struct System<Foo, Bar> {
foo: Foo,
bar: Bar,
baz: u32,
}
impl<Foo, Bar> System<Foo, Bar> {
pub fn with_foo<Value>(self, foo: Value) -> System<Value, Bar> {
let System { foo: _, bar, baz } = self;
System { foo, bar, baz }
}
pub fn with_bar<Value>(self, bar: Value) -> System<Foo, Value> {
let System { foo, bar: _, baz } = self;
System { foo, bar, baz }
}
pub fn with_baz(self, baz: u32) -> System<Foo, Bar> {
let System { foo, bar, baz: _ } = self;
System { foo, bar, baz }
}
}
impl System<(), ()> {
pub fn new() -> Self {
System { foo: (), bar: (), baz: 0 }
}
}
Existing builder crates would define a new SystemBuilder
type, which is not what I want. And the getset
crate doesn't seem to be able to change type.