rust-typed-builder
rust-typed-builder copied to clipboard
Require A or B to be set, but allow updating the other
I currently have the following builder:
struct MyStruct {
a: Option<&'static str>,
b: Option<&'static str>,
}
I want to be able to only call build if a OR b is provided, but I'd like to be able to set the other.
MyStruct::builder().build() // fail
MyStruct::builder().a("hello").build() // works
MyStruct::builder().b("world").build() // works
MyStruct::builder().a("hello").b("world").build() // works
Is there a way to do that?