Crate num_convert
source ·Expand description
§Generic traits for conversions between integer types.
This library provides various ways to convert to integer type from other types.
§Examples
assert_eq!(<u8 as FromByAdd<i8>>::from_by_add(-128_i8), 0_u8);
assert_eq!(<i16 as IntoByAdd<u16>>::into_by_add(i16::MIN), u16::MIN);
assert_eq!(<i8 as TryFromByAdd<u8>>::try_from_by_add(0_u8), Some(-128_i8));
assert_eq!(<i128 as TryIntoByAdd<u128>>::try_into_by_add(i128::MIN), Some(u128::MIN));
assert_eq!(<u8 as FromAs<i8>>::from_as(-128_i8), 128_u8);
assert_eq!(<u16 as IntoAs<u8>>::into_as(258_u16), 2_u8);
assert_eq!(<u8 as TryFromDigits<u16>>::from_digits(65_255_u16), Ok(255_u8));
assert_eq!(u64::MAX.sbits(), 64_u32);
assert_eq!(i8::tbits(), 8_u32);
assert_eq!(0i8.len(), 1_usize);
assert_eq!(u128::MAX.len(), 39_usize);
assert_eq!(<i32 as FromTuple>::from_5((true, false, 45_u8, 2023_u16, -60_i8,)),
[1_i32, 0_i32, 45_i32, 2023_i32, -60_i32]);
assert_eq!(<i16 as TryFromIntStr<&str>>::try_from_int_str("-2023"), Ok(-2023_i16));
assert_eq!(<u16 as TryFromIntStr<u128>>::try_from_int_str(1975_u128), Ok(1975_u16));
Structs§
- ConvertErrors
try_from_int_str
andtry_tup_to_arr8
andtry_tup_to_arr16
Structure for storing miscellaneous errors. - TryFromIntStrErr
try_from_int_str
An error which can be returned when parsing an integer or string. - TryTupToArrErr
try_tup_to_arr8
andtry_tup_to_arr16
A structure to store the error and its position.
Enums§
- IntStrError
try_from_int_str
Enum to store the various types of errors that can cause parsing an integer or string to fail. - MultiErrors
try_from_int_str
andtry_tup_to_arr8
andtry_tup_to_arr16
Enumeration error variants for thecrate
.
Traits§
- CastFromAs
cast_from_as
The CastFromAs trait for simple convert from value between integer types with possible overflow. - CastIntoAs
cast_into_as
The CastIntoAs trait for simple convert self value between integer types with possible overflow. - CheckRem
get_rem
Trait for checking the remainder. - The FromAs generic trait for convert from value between integer types with possible overflow.
- Generic trait for converting between integer types of different signs.
- FromTuple
tup8
andtup16
A trait to convert a tuple of different types to an array of integers. - A trait IntegerLen to determine the number of digits of integers.
- The IntoAs trait for convert into value between integer types with possible overflow.
- A generic trait for converting into possible types with different signs.
- Sbits
bits
The Sbit trait for define the size of integer value in bits. - Tbits
bits
Generic trait for define the size of the integers type in bits. - ToMax
to_max
Trait to implement upper bounds on types. - ToMin
to_min
Trait to implement lower bounds on types. - ToZero
to_zero
Trait for implementing the null value of types. - Generic trait for converting between integer types within bounds of possible values.
- Generic trait for converting integer type digits to some integer type.
- TryFromIntStr
try_from_int_str
A generic trait for converting from str or integer to type integer. - A generic trait for converting into possible types.
- TryTupToArr
try_tup_to_arr8
andtry_tup_to_arr16
- TypeInfo
type_info
Trait for type info. - ValTypeInfo
val_type_info
Trait value type info.