Closed
Description
Two reasons:
- Different types need to deal with this differently (see examples below). Having only one way to do it causes confusion, because it forces you to return an
Option
, even when the function cannot returnNone
. The standard library is full of calls followed byunwrap
. - It is not useful to provide a generic way to do it (please correct me if I am wrong).
Examples:
- No function of
FromPrimitive
can ever returnNone
forBigInt
- Only the functions which accept negative numbers can return
None
forBigUint
- For the primitive types, each one has different constraints. For example,
FromPrimitive::<i8>::from_i32
can returnNone
because of overflow, whileFromPrimitive::<f64>::from_i32
cannot.
The only problem I see is in libtest/stats.rs
, where FromPrimitive
is used generically. I think however that we can figure it out.
I think the best solution would be have different implementations for each type.
cc @aturon
Metadata
Metadata
Assignees
Labels
No labels