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
Steps / History
Unresolved Questions
Feature gate:
#![feature(const_num_from_num)]This is a tracking issue for constifying the
impl From<U> for Tandimpl TryFrom<U> for Tfor conversions between the basic built in numeric types(bothTandUare one off32,f64,iX,uX). It also constifies the correspondingFromconversions forNonZeroUXandNonZeroIXand fromNonZeroUX/NonZeroIXtouX/iXof same type and signedness. AdditionallyAtomicUXfromuXandAtomicIXfromiX, 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
ascastsPublic API
# TODOSteps / History
(Try)Fromfor int types #86840Fromimpls of NonZero integer const. #90077Unresolved Questions