Skip to content

Stabilize trait ZeroablePrimitive #698

@dhardy

Description

@dhardy

Proposal

Stabilize core::num::ZeroablePrimitive, keeping it sealed (and unsafe).

Problem statement

Since Rust 1.79, core::num::NonZero<T> is stable for T: ZeroablePrimitive. Yet, since ZeroablePrimitive is unstable, it is impossible to write generic code over NonZero.

Motivating examples or use cases

easy_cast::Cast supports numeric type conversions, a little like Into and TryInto but with different semantics. It has been requested that this support NonZero types.

The implementation of this should be fairly simple: kas-gui/easy-cast#36

Alternatives

Every "generic impl" over NonZero must instead be non-generic, likely repeated for a number of types or combinations of types using macro_rules!. The implementation of easy_cast::Conv over primitive integer types uses 29 invocations of macros, many of them recursive (covering 12 × 11 = 132 combinations IIRC).

Links and related work

Tracking issue for NonZero: rust-lang/rust#120257

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions