Skip to content

Add checked/overflowing/wrapping numeric casts #32421

Closed
@digama0

Description

@digama0

Currently, there are functions

fn checked_add(self, other: u8) -> Option<u8>
fn saturating_add(self, other: u8) -> u8
fn wrapping_add(self, rhs: u8) -> u8
fn overflowing_add(self, rhs: u8) -> (u8, bool)

for addition on u8. We should have this functionality also for casts, that is, functions like

fn checked_cast(self: u32) -> Option<u8>
fn saturating_cast(self: u32) -> u8
fn wrapping_cast(self: u32) -> u8
fn overflowing_cast(self: u32) -> (u8, bool)

with the obvious implementations. Specific traits for this functionality are up for debate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions