FromByAdd

Trait FromByAdd 

Source
pub trait FromByAdd<T> {
    // Required method
    fn from_by_add(n: T) -> Self;
}
Expand description

Generic trait for converting between integer types of different signs.

  • Converting types with different signs of the same size in bits.
  • A normal conversion of same-signed types to a larger integral type.
  • It is possible to convert types with different signs to a larger integer type.

§Usage

Basic use of the trait.

use num_convert::FromByAdd;

assert_eq!(<u8 as FromByAdd<i8>>::from_by_add(-123_i8), 5_u8);
assert_eq!(<u8>::from_by_add(100_i8), 228_u8);

§Examples

Converting integer types with different signs.

assert_eq!(<u8 as FromByAdd<i8>>::from_by_add(-128_i8), 0_u8);
assert_eq!(<i8 as FromByAdd<u8>>::from_by_add(255_u8), 127_i8);

Converting integer types with the same sign.

assert_eq!(<i16 as FromByAdd<i8>>::from_by_add(-128_i8), -128_i16);
assert_eq!(<u16 as FromByAdd<u8>>::from_by_add(0_u8), 0_u16);

Conversion of integer types with different signs to a larger type.

assert_eq!(<u16 as FromByAdd<i8>>::from_by_add(-128_i8), 0_u16);
assert_eq!(<i16 as FromByAdd<u8>>::from_by_add(255_u8), 127_i16);

Required Methods§

Source

fn from_by_add(n: T) -> Self

Converts one input integer type to another integer output type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromByAdd<i8> for i8

Source§

fn from_by_add(n: Self) -> Self

Returns the same type i8.

Source§

impl FromByAdd<i8> for i16

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to i16 losslessly.

Source§

impl FromByAdd<i8> for i32

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to i32 losslessly.

Source§

impl FromByAdd<i8> for i64

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to i64 losslessly.

Source§

impl FromByAdd<i8> for i128

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to i128 losslessly.

Source§

impl FromByAdd<i8> for isize

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to isize losslessly.

Source§

impl FromByAdd<i8> for u8

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent u8.

Source§

impl FromByAdd<i8> for u16

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent u16.

Source§

impl FromByAdd<i8> for u32

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent u32.

Source§

impl FromByAdd<i8> for u64

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent u64.

Source§

impl FromByAdd<i8> for u128

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent u128.

Source§

impl FromByAdd<i8> for usize

Source§

fn from_by_add(n: i8) -> Self

Converts i8 to equvalent usize.

Source§

impl FromByAdd<i16> for i16

Source§

fn from_by_add(n: Self) -> Self

Returns the same type i16.

Source§

impl FromByAdd<i16> for i32

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to i32 losslessly.

Source§

impl FromByAdd<i16> for i64

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to i64 losslessly.

Source§

impl FromByAdd<i16> for i128

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to i128 losslessly.

Source§

impl FromByAdd<i16> for isize

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to isize losslessly.

Source§

impl FromByAdd<i16> for u16

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to equvalent u16.

Source§

impl FromByAdd<i16> for u32

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to equvalent u32.

Source§

impl FromByAdd<i16> for u64

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to equvalent u64.

Source§

impl FromByAdd<i16> for u128

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to equvalent u128.

Source§

impl FromByAdd<i16> for usize

Source§

fn from_by_add(n: i16) -> Self

Converts i16 to equvalent usize.

Source§

impl FromByAdd<i32> for i32

Source§

fn from_by_add(n: Self) -> Self

Returns the same type i32.

Source§

impl FromByAdd<i32> for i64

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to i64 losslessly.

Source§

impl FromByAdd<i32> for i128

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to i128 losslessly.

Source§

impl FromByAdd<i32> for isize

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to isize losslessly.

Source§

impl FromByAdd<i32> for u32

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to equvalent u32.

Source§

impl FromByAdd<i32> for u64

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to equvalent u64.

Source§

impl FromByAdd<i32> for u128

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to equvalent u128.

Source§

impl FromByAdd<i32> for usize

Source§

fn from_by_add(n: i32) -> Self

Converts i32 to equvalent usize.

Source§

impl FromByAdd<i64> for i64

Source§

fn from_by_add(n: Self) -> Self

Returns the same type i64.

Source§

impl FromByAdd<i64> for i128

Source§

fn from_by_add(n: i64) -> Self

Converts i64 to i128 losslessly.

Source§

impl FromByAdd<i64> for isize

Source§

fn from_by_add(n: i64) -> Self

Converts i64 to isize losslessly.

Source§

impl FromByAdd<i64> for u64

Source§

fn from_by_add(n: i64) -> Self

Converts i64 to equvalent u64.

Source§

impl FromByAdd<i64> for u128

Source§

fn from_by_add(n: i64) -> Self

Converts i64 to equvalent u128.

Source§

impl FromByAdd<i64> for usize

Source§

fn from_by_add(n: i64) -> Self

Converts i64 to equvalent usize.

Source§

impl FromByAdd<i128> for i128

Source§

fn from_by_add(n: Self) -> Self

Returns the same type i128.

Source§

impl FromByAdd<i128> for u128

Source§

fn from_by_add(n: i128) -> Self

Converts i128 to equvalent u128.

Source§

impl FromByAdd<isize> for i64

Source§

fn from_by_add(n: isize) -> Self

Converts isize to i64 losslessly.

Source§

impl FromByAdd<isize> for i128

Source§

fn from_by_add(n: isize) -> Self

Converts isize to i128 losslessly.

Source§

impl FromByAdd<isize> for isize

Source§

fn from_by_add(n: Self) -> Self

Returns the same type isize.

Source§

impl FromByAdd<isize> for u64

Source§

fn from_by_add(n: isize) -> Self

Converts isize to equvalent u64.

Source§

impl FromByAdd<isize> for u128

Source§

fn from_by_add(n: isize) -> Self

Converts isize to equvalent u128.

Source§

impl FromByAdd<isize> for usize

Source§

fn from_by_add(n: isize) -> Self

Converts isize to equvalent usize.

Source§

impl FromByAdd<u8> for i8

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent i8.

Source§

impl FromByAdd<u8> for i16

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent i16.

Source§

impl FromByAdd<u8> for i32

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent i32.

Source§

impl FromByAdd<u8> for i64

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent i64.

Source§

impl FromByAdd<u8> for i128

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent i128.

Source§

impl FromByAdd<u8> for isize

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to equvalent isize.

Source§

impl FromByAdd<u8> for u8

Source§

fn from_by_add(n: Self) -> Self

Returns the same type u8.

Source§

impl FromByAdd<u8> for u16

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to u16 losslessly.

Source§

impl FromByAdd<u8> for u32

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to u32 losslessly.

Source§

impl FromByAdd<u8> for u64

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to u64 losslessly.

Source§

impl FromByAdd<u8> for u128

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to u128 losslessly.

Source§

impl FromByAdd<u8> for usize

Source§

fn from_by_add(n: u8) -> Self

Converts u8 to usize losslessly.

Source§

impl FromByAdd<u16> for i16

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to equvalent i16.

Source§

impl FromByAdd<u16> for i32

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to equvalent i32.

Source§

impl FromByAdd<u16> for i64

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to equvalent i64.

Source§

impl FromByAdd<u16> for i128

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to equvalent i128.

Source§

impl FromByAdd<u16> for isize

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to equvalent isize.

Source§

impl FromByAdd<u16> for u16

Source§

fn from_by_add(n: Self) -> Self

Returns the same type u16.

Source§

impl FromByAdd<u16> for u32

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to u32 losslessly.

Source§

impl FromByAdd<u16> for u64

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to u64 losslessly.

Source§

impl FromByAdd<u16> for u128

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to u128 losslessly.

Source§

impl FromByAdd<u16> for usize

Source§

fn from_by_add(n: u16) -> Self

Converts u16 to usize losslessly.

Source§

impl FromByAdd<u32> for i32

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to equvalent i32.

Source§

impl FromByAdd<u32> for i64

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to equvalent i64.

Source§

impl FromByAdd<u32> for i128

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to equvalent i128.

Source§

impl FromByAdd<u32> for isize

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to equvalent isize.

Source§

impl FromByAdd<u32> for u32

Source§

fn from_by_add(n: Self) -> Self

Returns the same type u32.

Source§

impl FromByAdd<u32> for u64

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to u64 losslessly.

Source§

impl FromByAdd<u32> for u128

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to u128 losslessly.

Source§

impl FromByAdd<u32> for usize

Source§

fn from_by_add(n: u32) -> Self

Converts u32 to usize losslessly.

Source§

impl FromByAdd<u64> for i64

Source§

fn from_by_add(n: u64) -> Self

Converts u64 to equvalent i64.

Source§

impl FromByAdd<u64> for i128

Source§

fn from_by_add(n: u64) -> Self

Converts u64 to equvalent i128.

Source§

impl FromByAdd<u64> for isize

Source§

fn from_by_add(n: u64) -> Self

Converts u64 to equvalent isize.

Source§

impl FromByAdd<u64> for u64

Source§

fn from_by_add(n: Self) -> Self

Returns the same type u64.

Source§

impl FromByAdd<u64> for u128

Source§

fn from_by_add(n: u64) -> Self

Converts u64 to u128 losslessly.

Source§

impl FromByAdd<u64> for usize

Source§

fn from_by_add(n: u64) -> Self

Converts u64 to usize losslessly.

Source§

impl FromByAdd<u128> for i128

Source§

fn from_by_add(n: u128) -> Self

Converts u128 to equvalent i128.

Source§

impl FromByAdd<u128> for u128

Source§

fn from_by_add(n: Self) -> Self

Returns the same type u128.

Source§

impl FromByAdd<usize> for i64

Source§

fn from_by_add(n: usize) -> Self

Converts usize to equvalent i64.

Source§

impl FromByAdd<usize> for i128

Source§

fn from_by_add(n: usize) -> Self

Converts usize to equvalent i128.

Source§

impl FromByAdd<usize> for isize

Source§

fn from_by_add(n: usize) -> Self

Converts usize to equvalent isize.

Source§

impl FromByAdd<usize> for u64

Source§

fn from_by_add(n: usize) -> Self

Converts usize to u64 losslessly.

Source§

impl FromByAdd<usize> for u128

Source§

fn from_by_add(n: usize) -> Self

Converts usize to u128 losslessly.

Source§

impl FromByAdd<usize> for usize

Source§

fn from_by_add(n: Self) -> Self

Returns the same type usize.

Implementors§