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
Considering try_
prefix for creating nutype objects
#91
Comments
Hi, thank you for your appreciation of crate. The idea to use The fact that I am not sure, maybe you miss this: if there is no validation, ::new() is not fallible, so it returns exactly a newtype (not Result)
You can derive #[nutype(
sanitize(trim, lowercase)
validate(not_empty, char_len_max = 20)
)]
#[derive(TryFrom)]
pub struct Username(String); Or if you'll use 0.4.0-beta.2: #[nutype(
sanitize(trim, lowercase),
validate(not_empty, char_len_max = 20),
derive(TryFrom),
)]
pub struct Username(String); (the new 0.4.0 version is going to be released soon). For now I am going to close the issue, but I am fine to answer your further questions or reconsider my decision if you put more arguments. Thank you! |
Consider fallible new is typically bad practice, I'm thinking that if a type has validation, no |
Hello! =)
Thanks your awesome work on
nutype
, it has been very helpful!I was thinking, since the
new()
method can fail, this could be better described by adding atry_
prefix (e.g. try_new()
).Since Rust already has the
TryFrom
trait (had a little trouble implementing it myself), I'd like to suggest that to be the de-facto way to create nutypes objects.What do you think?
The text was updated successfully, but these errors were encountered: