src/maputil.rs

changeset 94
1f19c6bbf07b
parent 92
e11986179a4b
equal deleted inserted replaced
93:123f7f38e161 94:1f19c6bbf07b
1 /*! 1 /*!
2 Utilities for mapping over various container types. 2 Utilities for mapping over various container types.
3 */ 3 */
4 4
5 use itertools::izip; 5 use itertools::izip;
6 #[cfg(feature = "nightly")] 6 #[cfg(nightly)]
7 use std::mem::MaybeUninit; 7 use std::mem::MaybeUninit;
8 8
9 /// Trait for a fixed-length container type. 9 /// Trait for a fixed-length container type.
10 /// 10 ///
11 /// Implemented by [`Loc`][crate::loc::Loc] vectors, [`Cube`][crate::sets::Cube]s, 11 /// Implemented by [`Loc`][crate::loc::Loc] vectors, [`Cube`][crate::sets::Cube]s,
350 /// `next` at most `N` times, the iterator can still be used afterwards to 350 /// `next` at most `N` times, the iterator can still be used afterwards to
351 /// retrieve the remaining items. 351 /// retrieve the remaining items.
352 /// 352 ///
353 /// If `iter.next()` panicks, all items already yielded by the iterator are 353 /// If `iter.next()` panicks, all items already yielded by the iterator are
354 /// dropped. 354 /// dropped.
355 #[cfg(feature = "nightly")] 355 #[cfg(nightly)]
356 #[inline] 356 #[inline]
357 pub(crate) fn collect_into_array_unchecked<T, I: Iterator<Item = T>, const N: usize>( 357 pub(crate) fn collect_into_array_unchecked<T, I: Iterator<Item = T>, const N: usize>(
358 mut iter: I, 358 mut iter: I,
359 ) -> [T; N] { 359 ) -> [T; N] {
360 if N == 0 { 360 if N == 0 {
411 } 411 }
412 412
413 unreachable!("Something went wrong with iterator length") 413 unreachable!("Something went wrong with iterator length")
414 } 414 }
415 415
416 #[cfg(not(feature = "nightly"))] 416 #[cfg(not(nightly))]
417 #[inline] 417 #[inline]
418 pub(crate) fn collect_into_array_unchecked<T, I: Iterator<Item = T>, const N: usize>( 418 pub(crate) fn collect_into_array_unchecked<T, I: Iterator<Item = T>, const N: usize>(
419 iter: I, 419 iter: I,
420 ) -> [T; N] { 420 ) -> [T; N] {
421 match iter.collect::<Vec<T>>().try_into() { 421 match iter.collect::<Vec<T>>().try_into() {

mercurial