Skip to content

Tracking Issue for const_num_from_num #87852

Closed
@usbalbin

Description

@usbalbin

Feature gate: #![feature(const_num_from_num)]

This is a tracking issue for constifying the impl From<U> for T and impl TryFrom<U> for T for conversions between the basic built in numeric types(both T and U are one of f32, f64, iX, uX). It also constifies the corresponding From conversions for NonZeroUX and NonZeroIX and from NonZeroUX/NonZeroIX to uX/iX of same type and signedness. Additionally AtomicUX from uX and AtomicIX from iX, this is however only for types of same size.

Note that all of this does not add any new implementations, it only constifies the existing ones.

In short, this will enable things like below without having to use as casts

const FOO_U32: u32 = u32::from(bar_returing_u16()); // u16 -> u32
const BAZ_F32: f32 = f32::from(bar_returing_u8());  // u8 -> f32

const FROM_NONZERO_U8: u8 = u8::from(bar_returing_nonzero_u8()); // NonZeroU8 -> u8
const NONZERO_FROM_SMALLER: NonZeroU32 = NonZeroU32::from(bar_returing_nonzero_u8()); // NonZeroU8 -> NonZeroU32

const ATOMIC_FROM_U8: AtomicU8 = AtomicU8::from(bar_returing_u8()); // u8 -> AtomicU8

Public API

# TODO

Steps / History

Unresolved Questions

  • None yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_trait_impl`#![feature(const_trait_impl)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions