Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checked/overflowing/wrapping numeric casts #32421

Closed
digama0 opened this issue Mar 22, 2016 · 2 comments
Closed

Add checked/overflowing/wrapping numeric casts #32421

digama0 opened this issue Mar 22, 2016 · 2 comments

Comments

@digama0
Copy link
Contributor

digama0 commented Mar 22, 2016

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.

@petrochenkov
Copy link
Contributor

This is covered by rust-lang/rfcs#1218
It would be great if you described your use cases for these functions in the RFC comments.

@digama0
Copy link
Contributor Author

digama0 commented Mar 22, 2016

Great! I'll go over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants