1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::{Fragment, Growth, SplitVec};
use alloc::vec::Vec;

/// Converts self into a collection of [`Fragment`]s.
pub trait IntoFragments<T> {
    /// Converts self into a collection of [`Fragment`]s.
    fn into_fragments(self) -> impl Iterator<Item = Fragment<T>>;
}

impl<T> IntoFragments<T> for Vec<T> {
    fn into_fragments(self) -> impl Iterator<Item = Fragment<T>> {
        [Fragment::from(self)].into_iter()
    }
}

impl<T, const N: usize> IntoFragments<T> for [Vec<T>; N] {
    fn into_fragments(self) -> impl Iterator<Item = Fragment<T>> {
        self.into_iter().map(Fragment::from)
    }
}

impl<T> IntoFragments<T> for Vec<Vec<T>> {
    fn into_fragments(self) -> impl Iterator<Item = Fragment<T>> {
        self.into_iter().map(Fragment::from)
    }
}

impl<T, G: Growth> IntoFragments<T> for SplitVec<T, G> {
    fn into_fragments(self) -> impl Iterator<Item = Fragment<T>> {
        self.fragments.into_iter()
    }
}