Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate each field individually #105

Open
Zizico2 opened this issue Jul 21, 2023 · 4 comments
Open

Validate each field individually #105

Zizico2 opened this issue Jul 21, 2023 · 4 comments

Comments

@Zizico2
Copy link

Zizico2 commented Jul 21, 2023

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();.

@idanarye
Copy link
Owner

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...

@Zizico2
Copy link
Author

Zizico2 commented Jul 24, 2023

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?

@idanarye
Copy link
Owner

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

@l-7-l
Copy link

l-7-l commented Aug 23, 2024

Maybe you could use newtype instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants