idanarye/rust-typed-builder

Validate each field individually

Opened this issue · 3 comments

Is it possible (would it be possible?) to have each field validated when it is added?

It could look something like Foo::builder().x(1).try_into().y(2).try_into().z(3).try_into().build();.

What does try_into have to do with anything? Shouldn't individual field validation mean that a setter returns a Result?

Either way, unlike #67 this is not something we can solve with a trait impl because we'd need one for each field. Maybe when const macros would support &str...

Yeah, idk why I thought of try_into.

This would make most sense I guess? Foo::builder().x(1)?.y(2)?.z(3)?.build();.

Idk much about how typed_builder works. Do you think I couldn't find a way to make this work, that you would accept?

It can be done, but we need to come up with a good syntax.