IntoArray

Trait IntoArray 

Source
pub trait IntoArray<E, const N: usize> {
    // Required method
    fn into_array(self) -> [E; N];

    // Provided method
    fn as_array(&self) -> [E; N]
       where Self: Clone { ... }
}
Expand description

The IntoArray trait is used to convert a collection into a fixed-size array.

This trait provides two methods:

  • into_array, which consumes the collection and returns a fixed-size array [E; N].
  • as_array, which borrows the collection (without consuming it) and returns a new fixed-size array [E; N] by cloning the collection.

This can be useful when a collection needs to be represented as an array with a known, fixed size.

§Type Parameters

  • E: The type of the elements in the resulting array.
  • N: The fixed number of elements in the array.

§Examples

Basic usage with consumption:

use mdmath_core::IntoArray;
struct MyCollection;

impl IntoArray< i32, 3 > for MyCollection
{
  fn into_array( self ) -> [ i32; 3 ]
  {
    [ 1, 2, 3 ]
  }
}

let coll = MyCollection;
let array = coll.into_array();
assert_eq!( array, [ 1, 2, 3 ] );

Basic usage without consumption:

use mdmath_core::IntoArray;
struct MyCollection;

impl IntoArray< i32, 3 > for MyCollection
{
  fn into_array( self ) -> [ i32; 3 ]
  {
    [ 1, 2, 3 ]
  }
}

let coll = MyCollection;
let array = coll.as_array();
assert_eq!( array, [ 1, 2, 3 ] );

Required Methods§

Source

fn into_array(self) -> [E; N]

Consumes the collection and returns a fixed-size array.

§Returns
  • [E; N]: The fixed-size array produced from the collection.

Provided Methods§

Source

fn as_array(&self) -> [E; N]
where Self: Clone,

Returns a fixed-size array without consuming the collection.

This method clones the collection and then converts it into an array using the into_array method.

§Constraints

The collection must implement Clone.

§Returns
  • [E; N]: The fixed-size array produced from a clone of the collection.

Implementations on Foreign Types§

Source§

impl<E> IntoArray<E, 0> for ()

Source§

impl<E> IntoArray<E, 1> for (E,)

Source§

impl<E> IntoArray<E, 2> for (E, E)

Source§

impl<E> IntoArray<E, 3> for (E, E, E)

Source§

impl<E> IntoArray<E, 4> for (E, E, E, E)

Source§

impl<E, const N: usize> IntoArray<E, N> for &[E]
where [E; N]: for<'data> TryFrom<&'data [E]>,

Source§

impl<E, const N: usize> IntoArray<E, N> for [E; N]

Source§

impl<T, E, const N: usize> IntoArray<E, N> for &T
where T: IntoArray<E, N> + Clone,

Source§

impl<T, E, const N: usize> IntoArray<E, N> for &mut T
where T: IntoArray<E, N> + Clone,

Implementors§

Source§

impl IntoArray<usize, 0> for Dim<[usize; 0]>

Source§

impl IntoArray<usize, 1> for Dim<[usize; 1]>

Source§

impl IntoArray<usize, 2> for Dim<[usize; 2]>

Source§

impl IntoArray<usize, 3> for Dim<[usize; 3]>