TryTupToArr

Trait TryTupToArr 

Source
pub trait TryTupToArr<U> {
    type A;

    // Required method
    fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>;
}
Available on crate features try_tup_to_arr8 and try_tup_to_arr16 only.
Expand description

A trait to convert a tuple of different types to an array of integers, a possible conversion error.

  • Without using the heap.
  • Returns an error if the value is out of range.

§Usage

Basic use of the trait.

use num_convert::TryTupToArr;

assert_eq!(TryTupToArr::<i32>::try_into_arr((45_u8, 2023_u16, -60_i8,)),
Ok([45_i32, 2023_i32, -60_i32]));

let arr: [i16; 3] = ("45", 2023_u16, true,).try_into_arr().unwrap();
assert_eq!(arr, [45_i16, 2023_i16, 1_i16]);

§Examples

assert_eq!(TryTupToArr::<i16>::try_into_arr(("-12345", 9923_u16, false,)),
Ok([-12345_i16, 9923_i16, 0_i16]));

assert_eq!(TryTupToArr::try_into_arr((45_u8, 2023_u16, -53_i8,))
.unwrap().iter().sum::<i32>(), 2015i32);

assert!(TryTupToArr::<i16>::try_into_arr(("6032023", 2023_u16, true,)).is_err());

Required Associated Types§

Source

type A

Output type array of integers.

Required Methods§

Source

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Returns an array of integers or a conversion error.

Implementations on Foreign Types§

Source§

impl<U, T0> TryTupToArr<U> for (T0,)
where U: TryFromIntStr<T0>,

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0,) to array [Self; 1].

Source§

type A = [U; 1]

Source§

impl<U, T0, T1> TryTupToArr<U> for (T0, T1)
where U: TryFromIntStr<T0> + TryFromIntStr<T1>,

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1,) to array [Self; 2].

Source§

type A = [U; 2]

Source§

impl<U, T0, T1, T2> TryTupToArr<U> for (T0, T1, T2)
where U: TryFromIntStr<T0> + TryFromIntStr<T1> + TryFromIntStr<T2>,

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2,) to array [Self; 3].

Source§

type A = [U; 3]

Source§

impl<U, T0, T1, T2, T3> TryTupToArr<U> for (T0, T1, T2, T3)
where U: TryFromIntStr<T0> + TryFromIntStr<T1> + TryFromIntStr<T2> + TryFromIntStr<T3>,

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3,) to array [Self; 4].

Source§

type A = [U; 4]

Source§

impl<U, T0, T1, T2, T3, T4> TryTupToArr<U> for (T0, T1, T2, T3, T4)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4,) to array [Self; 5].

Source§

type A = [U; 5]

Source§

impl<U, T0, T1, T2, T3, T4, T5> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5,) to array [Self; 6].

Source§

type A = [U; 6]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6,) to array [Self; 7].

Source§

type A = [U; 7]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7,) to array [Self; 8].

Source§

type A = [U; 8]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8,) to array [Self; 9].

Source§

type A = [U; 9]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,) to array [Self; 10].

Source§

type A = [U; 10]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,) to array [Self; 11].

Source§

type A = [U; 11]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,) to array [Self; 12].

Source§

type A = [U; 12]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,) to array [Self; 13].

Source§

type A = [U; 13]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,) to array [Self; 14].

Source§

type A = [U; 14]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,) to array [Self; 15].

Source§

type A = [U; 15]

Source§

impl<U, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> TryTupToArr<U> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)

Available on crate features try_tup_to_arr8 or try_tup_to_arr16 only.
Source§

fn try_into_arr(self) -> Result<Self::A, TryTupToArrErr>

Converts tuple (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,) to array [Self; 16].

Source§

type A = [U; 16]

Implementors§