pub trait FromIteratorFixed<T, const N: usize> {
// Required method
fn from_iter_fixed<I: Iterator<Item = T>>(
iter_fixed: IteratorFixed<I, N>,
) -> Self;
}
Expand description
Conversion from an IteratorFixed
.
By implementing FromIteratorFixed
for a type, you define how it will be
created from an iterator of fixed size.
FromIteratorFixed::from_iter_fixed()
is rarely called explicitly, and is instead
used through IteratorFixed::collect()
method. See IteratorFixed::collect()
’s
documentation for more examples.
See also: crate::IntoIteratorFixed
.
Required Methods§
Sourcefn from_iter_fixed<I: Iterator<Item = T>>(
iter_fixed: IteratorFixed<I, N>,
) -> Self
fn from_iter_fixed<I: Iterator<Item = T>>( iter_fixed: IteratorFixed<I, N>, ) -> Self
Creates a value from a fixed size iterator.
Basic usage:
use iter_fixed::{IntoIteratorFixed, FromIteratorFixed};
let two_four_six = [1, 2, 3].into_iter_fixed().map(|x| 2 * x);
let a = <[i32; 3]>::from_iter_fixed(two_four_six);
assert_eq!(a, [2, 4, 6]);
Using IteratorFixed::collect()
to implicitly use FromIteratorFixed
:
use iter_fixed::IntoIteratorFixed;
let two_four_six = [1, 2, 3].into_iter_fixed().map(|x| 2 * x);
let a: [i32; 3] = two_four_six.collect();
assert_eq!(a, [2, 4, 6]);
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<T, const N: usize> FromIteratorFixed<T, N> for [T; N]
impl<T, const N: usize> FromIteratorFixed<T, N> for [T; N]
Source§fn from_iter_fixed<I: Iterator<Item = T>>(
iter_fixed: IteratorFixed<I, N>,
) -> Self
fn from_iter_fixed<I: Iterator<Item = T>>( iter_fixed: IteratorFixed<I, N>, ) -> Self
Creates an array from a fixed size iterator.
Basic usage:
use iter_fixed::{IntoIteratorFixed, FromIteratorFixed};
let two_four_six = [1, 2, 3].into_iter_fixed().map(|x| 2 * x);
let a = <[i32; 3]>::from_iter_fixed(two_four_six);
assert_eq!(a, [2, 4, 6]);
Using IteratorFixed::collect()
to implicitly use FromIteratorFixed
:
use iter_fixed::IntoIteratorFixed;
let two_four_six = [1, 2, 3].into_iter_fixed().map(|x| 2 * x);
let a: [i32; 3] = two_four_six.collect();
assert_eq!(a, [2, 4, 6]);