How to convert it to a generic function? This function works perfectly on integer, yet when I've tried to make it generic so it works on any integer not just i32 I cannot for the life of me make it.
extern crate num;
use num::Integer;
pub fn reverse_regetni<T: Integer + std::fmt::Display + std::str::FromStr>(int: T)->T
{
let mut stringed = int.to_string();
let is_negative = int < T::zero();
let chars_reversed:String = stringed.chars().skip(if is_negative{1}else{0}).collect();
let res = chars_reversed.parse::<T>().unwrap();
if is_negative{res * -1}else{res}
}
No; Integer is for both signed and unsigned integer types. If you need negative numbers, you’ll also need the Signed trait.
They’re unrelated to performing arithmetic, so it makes sense to leave them out of the Integer trait. Otherwise, a user-defined integer type would have to include a string parser to be an Integer.