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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use alloc::{string::String, vec::Vec, collections::{BTreeMap, BTreeSet}};
use crate::{FromInternalIterator, InternalIterator, IntoInternalIterator, IteratorExt};

impl<A> FromInternalIterator<A> for Vec<A> {
    fn from_iter<T>(iter: T) -> Self
    where
        T: IntoInternalIterator<Item = A>
    {
        let mut result = Vec::new();
        iter.into_internal_iter().for_each(|item| {
            result.push(item);
        });
        result
    }
}

impl FromInternalIterator<char> for String {
    fn from_iter<T>(iter: T) -> Self
    where
        T: IntoInternalIterator<Item = char>
    {
        let mut result = String::new();
        iter.into_internal_iter().for_each(|item| {
            result.push(item);
        });
        result
    }
}

impl<A: Ord> FromInternalIterator<A> for BTreeSet<A> {
    fn from_iter<T>(iter: T) -> Self
    where
        T: IntoInternalIterator<Item = A>
    {
        let mut result = BTreeSet::new();
        iter.into_internal_iter().for_each(|item| {
            result.insert(item);
        });
        result
    }
}

impl<K: Ord, V> FromInternalIterator<(K, V)> for BTreeMap<K, V> {
    fn from_iter<T>(iter: T) -> Self
    where
        T: IntoInternalIterator<Item = (K, V)>
    {
        let mut result = BTreeMap::new();
        iter.into_internal_iter().for_each(|(k, v)| {
            result.insert(k, v);
        });
        result
    }
}

crate::into_internal_impls! {
    ['a, T] &'a Vec<T>,
    ['a, T] &'a mut Vec<T>,
    [T] Vec<T>,
    ['a, T] &'a BTreeSet<T>,
    [T] BTreeSet<T>,
    ['a, K, V] &'a BTreeMap<K, V>,
    ['a, K, V] &'a mut BTreeMap<K, V>,
    [K, V] BTreeMap<K, V>,
}