rust-typed-builder icon indicating copy to clipboard operation
rust-typed-builder copied to clipboard

Require A or B to be set, but allow updating the other

Open gusinacio opened this issue 11 months ago • 0 comments

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?

gusinacio avatar Nov 26 '24 01:11 gusinacio