Tracking Issue for `integer_casts`
Open
@orlp is already working on this.
Since Jun 7, 2026.
C-tracking-issue
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
- ACP: https://github.com/rust-lang/libs-team/issues/788
- Implementation: https://github.com/rust-lang/rust/pull/157402
- Final comment period (FCP)^1
- Stabilization PR
Unresolved Questions
- What should happen to the current unstable narrow/truncate API?
- Should the
NonZerotypes be included?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.