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§
Sourcefn into_array(self) -> [E; N]
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.