Feature gate: #![feature(integer_casts)]
This is a tracking issue for the addition of saturating, wrapping, checked, unchecked, and strict casts between integer types.
Public API
For each built-in integer type T the following methods are added:
impl T {
/// Converts `self` to the target integer type, saturating at the nearest edge
/// of the target type's domain if the value does not lie in within it.
fn saturating_cast<T: BoundedCastFromInt<Self>>(self) -> T;
/// Converts `self` to the target integer type, wrapping around at the
/// boundary of the target type.
fn wrapping_cast<T: BoundedCastFromInt<Self>>(self) -> T;
/// Converts `self` to the target integer type, returning `None` if the value
/// does not lie in the target type's domain.
fn checked_cast<T: CheckedCastFromInt<Self>>(self) -> Option<T>;
/// Equivalent to `self.checked_cast::<Int>().unwrap()`.
fn strict_cast<T: CheckedCastFromInt<Self>>(self) -> T;
/// Equivalent to `self.checked_cast::<Int>().unwrap_unchecked()`.
unsafe fn unchecked_cast<T: CheckedCastFromInt<Self>>(self) -> T;
}
Steps / History
Unresolved Questions
Feature gate:
#![feature(integer_casts)]This is a tracking issue for the addition of
saturating,wrapping,checked,unchecked, andstrictcasts between integer types.Public API
For each built-in integer type
Tthe following methods are added:Steps / History
integer_casts#157402Unresolved Questions
NonZerotypes be included?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩