pub trait CastIntoAs {
// Required methods
fn into_i8(self) -> i8;
fn into_i16(self) -> i16;
fn into_i32(self) -> i32;
fn into_i64(self) -> i64;
fn into_isize(self) -> isize;
fn into_i128(self) -> i128;
fn into_u8(self) -> u8;
fn into_u16(self) -> u16;
fn into_u32(self) -> u32;
fn into_u64(self) -> u64;
fn into_usize(self) -> usize;
fn into_u128(self) -> u128;
}cast_into_as only.Expand description
The CastIntoAs trait for simple convert self value between integer types with possible overflow.
- No generic data type used in the trait definition.
- Easy implementation when used as a super trait.
§Usage
Basic use of the trait.
use num_convert::CastIntoAs;
assert_eq!(<u16 as CastIntoAs>::into_u8(255_u16), 255_u8);
assert_eq!(258_u16.into_u8(), 2_u8);§Examples
assert_eq!(128_u8.into_i8(), -128_i8);
assert_eq!(512_u16.into_u8(), 0_u8);Required Methods§
Sourcefn into_i16(self) -> i16
fn into_i16(self) -> i16
Converts the value of self to i16. Overflow possible during conversion.
Sourcefn into_i32(self) -> i32
fn into_i32(self) -> i32
Converts the value of self to i32. Overflow possible during conversion.
Sourcefn into_i64(self) -> i64
fn into_i64(self) -> i64
Converts the value of self to i64. Overflow possible during conversion.
Sourcefn into_isize(self) -> isize
fn into_isize(self) -> isize
Converts the value of self to isize. Overflow possible during conversion.
Sourcefn into_i128(self) -> i128
fn into_i128(self) -> i128
Converts the value of self to i128. Overflow possible during conversion.
Sourcefn into_u16(self) -> u16
fn into_u16(self) -> u16
Converts the value of self to u16. Overflow possible during conversion.
Sourcefn into_u32(self) -> u32
fn into_u32(self) -> u32
Converts the value of self to u32. Overflow possible during conversion.
Sourcefn into_u64(self) -> u64
fn into_u64(self) -> u64
Converts the value of self to u64. Overflow possible during conversion.
Sourcefn into_usize(self) -> usize
fn into_usize(self) -> usize
Converts the value of self to usize. Overflow possible during conversion.