ramp icon indicating copy to clipboard operation
ramp copied to clipboard

[feature request] Checked primitive type conversion

Open kunerd opened this issue 10 years ago • 3 comments

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

fn to_i64(&self) -> Option<i64> { ... }

kunerd avatar Jul 11 '15 12:07 kunerd

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

rozbb avatar Jun 18 '18 21:06 rozbb

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, ...

kunerd avatar Jun 21 '18 19:06 kunerd

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?

rozbb avatar Jun 21 '18 20:06 rozbb