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

[feature request] Checked primitive type conversion #13

Open
kunerd opened this issue Jul 11, 2015 · 3 comments
Open

[feature request] Checked primitive type conversion #13

kunerd opened this issue Jul 11, 2015 · 3 comments

Comments

@kunerd
Copy link
Contributor

kunerd commented Jul 11, 2015

Add checked conversion for Int to primitive types (u8, u16, u32, ...), similar as in num::bigint trait.

fn to_i64(&self) -> Option<i64> { ... }
@kunerd kunerd changed the title [feature request] To primitive type conversion [feature request] Checked primitive type conversion Jul 11, 2015
@rozbb
Copy link
Collaborator

rozbb commented Jun 18, 2018

This is doable. Do you have a motivating use case for a feature like this?

@kunerd
Copy link
Contributor Author

kunerd commented Jun 21, 2018

I think my main motivation back in the days was that I used ramp to implement algorithms which work in a cryptographic context, e.g. do some operations with encrypted values and in the end get the plain (decrypted) result. So my inputs where something like u8, u16 and so on, the encrypted values were ramps big ints and my result in the end should be again u8, u16, ...

@rozbb
Copy link
Collaborator

rozbb commented Jun 21, 2018

Hmm I see. For the sake of brevity, I would hold off on implementing this inside ramp, since it can be done pretty easily with an Int::to_str_radix followed by a u16::from_str_radix or what have you. Is that reasonable?

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