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§

ConvertErrorstry_from_int_str and try_tup_to_arr8 and try_tup_to_arr16
Structure for storing miscellaneous errors.
TryFromIntStrErrtry_from_int_str
An error which can be returned when parsing an integer or string.
TryTupToArrErrtry_tup_to_arr8 and try_tup_to_arr16
A structure to store the error and its position.

Enums§

IntStrErrortry_from_int_str
Enum to store the various types of errors that can cause parsing an integer or string to fail.
MultiErrorstry_from_int_str and try_tup_to_arr8 and try_tup_to_arr16
Enumeration error variants for the crate.

Traits§

CastFromAscast_from_as
The CastFromAs trait for simple convert from value between integer types with possible overflow.
CastIntoAscast_into_as
The CastIntoAs trait for simple convert self value between integer types with possible overflow.
CheckRemget_rem
Trait for checking the remainder.
FromAs
The FromAs generic trait for convert from value between integer types with possible overflow.
FromByAdd
Generic trait for converting between integer types of different signs.
FromTupletup8 and tup16
A trait to convert a tuple of different types to an array of integers.
IntegerLen
A trait IntegerLen to determine the number of digits of integers.
IntoAs
The IntoAs trait for convert into value between integer types with possible overflow.
IntoByAdd
A generic trait for converting into possible types with different signs.
Sbitsbits
The Sbit trait for define the size of integer value in bits.
Tbitsbits
Generic trait for define the size of the integers type in bits.
ToMaxto_max
Trait to implement upper bounds on types.
ToMinto_min
Trait to implement lower bounds on types.
ToZeroto_zero
Trait for implementing the null value of types.
TryFromByAdd
Generic trait for converting between integer types within bounds of possible values.
TryFromDigits
Generic trait for converting integer type digits to some integer type.
TryFromIntStrtry_from_int_str
A generic trait for converting from str or integer to type integer.
TryIntoByAdd
A generic trait for converting into possible types.
TryTupToArrtry_tup_to_arr8 and try_tup_to_arr16
A trait to convert a tuple of different types to an array of integers, a possible conversion error.
TypeInfotype_info
Trait for type info.
ValTypeInfoval_type_info
Trait value type info.