-
Notifications
You must be signed in to change notification settings - Fork 39
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
Return Option
instead of panicking inside new
#21
Comments
Hi, Thanks for pointing this out @Lakelezz I fully agree that doing like My original plan was to use Even though the stabilization of It would be acceptable to have |
|
|
I would argue having an assert in new, also makes it harder for non_std, as a panic handler can be tripped. Therefor a panic handler has to be written |
I'm not sure there is trouble with panicking on no_std -- it's almost impossible to not have any panickable situations in a nontrivial program, but the panic handler can be a plain abort. Either way, with #60 on the way and TryInto available, what's left for this issue? Would it suffice to point to TryInto as a fallible alternative in the documentation of ::new()? |
I still would say having |
I also agree that using Option on new is a better default in general. |
Hello!
I was looking at the crate and read that
new
will panic if the value cannot be represented by the type.Understandably, uX's types require the
new
-function to be constructed as they are not integer primitives thusu31
cannot utilise the same construction as e.g.u32
.Nonetheless, when we look at e.g. NonZeroU32's new (and the other
NonZero
-types) - which is a custom integer too - it returnsOption
instead of panicking when the conditions are not met. This might an interesting guideline to follow.Hence my question: Might changing uX's
new
-functions to returnOption
be of interest?Mirroring
new_unchecked
could be feasible too but thestd
does not run assertions in them.If wanted, I would be willing to perform this change : )
Thanks for your time!
The text was updated successfully, but these errors were encountered: