Trait core_extensions::collections::IntoArray
source · [−]pub trait IntoArray {
type Array;
fn into_array(self) -> Self::Array;
}
Available on crate feature
collections
only.Expand description
Converts a fixed length collection to an array.
Features
Enabling the “rust_1_51” feature allows arrays of all lengths to implement this trait, otherwise it’s only implemented for arrays up to 32 elements long.
Examples
Tuples
use core_extensions::collections::IntoArray;
assert_eq!((2,).into_array(), [2]);
assert_eq!((2, 3).into_array(), [2, 3]);
assert_eq!((2, 3, 5).into_array(), [2, 3, 5]);
assert_eq!((2, 3, 5, 8).into_array(), [2, 3, 5, 8]);
Arrays
use core_extensions::collections::IntoArray;
assert_eq!([13].into_array(), [13]);
assert_eq!([13, 21].into_array(), [13, 21]);
assert_eq!([13, 21, 34].into_array(), [13, 21, 34]);
assert_eq!([13, 21, 34, 55].into_array(), [13, 21, 34, 55]);
Implementing this trait
use core_extensions::collections::IntoArray;
struct Pair<T>(T, T);
impl<T> IntoArray for Pair<T> {
type Array = [T; 2];
fn into_array(self) -> Self::Array {
[self.0, self.1]
}
}
let foo = Pair(3, 5);
assert_eq!(foo.into_array(), [3, 5]);
let bar = Pair("hello", "world");
assert_eq!(bar.into_array(), ["hello", "world"]);
Required Associated Types
Required Methods
sourcefn into_array(self) -> Self::Array
fn into_array(self) -> Self::Array
Converts the tuple to an array..