Closed
Description
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
- Implementation of conversions of primitive numbers: Constify implementations of
(Try)From
for int types #86840 - Implementation of conversions of atomic and non-zero integers: Make
From
impls of NonZero integer const. #90077 - Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- None yet.