Skip to content

Deprecate the FromPrimitive trait #16920

Closed
@aochagavia

Description

@aochagavia

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 return None. The standard library is full of calls followed by unwrap.
  • 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 return None for BigInt
  • Only the functions which accept negative numbers can return None for BigUint
  • For the primitive types, each one has different constraints. For example, FromPrimitive::<i8>::from_i32 can return None because of overflow, while FromPrimitive::<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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions