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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use core::ptr::Thin;
use crate::Bulk;
pub const trait AsBulk
{
/// Creates a bulk from a reference.
///
/// See the [crate documentation](crate) for more.
///
/// # Examples
///
/// ```
/// use bulks::*;
///
/// let v = [1, 2, 3];
/// let bulk = v.bulk();
/// let u: [_; _] = bulk.collect();
///
/// assert_eq!(u, [&1, &2, &3]);
/// ```
fn bulk<'a>(&'a self) -> <&'a Self as IntoBulk>::IntoBulk
where
&'a Self: ~const IntoBulk
{
self.into_bulk()
}
/// Creates a bulk from a mutable reference.
///
/// See the [crate documentation](crate) for more.
///
/// # Examples
///
/// ```
/// use bulks::*;
///
/// let mut v = [1, 2, 3];
/// let bulk = v.bulk_mut();
/// let u: [_; _] = bulk.map(|v| core::mem::replace(v, *v + 1))
/// .collect();
///
/// assert_eq!(v, [2, 3, 4]);
/// assert_eq!(u, [1, 2, 3]);
/// ```
fn bulk_mut<'a>(&'a mut self) -> <&'a mut Self as IntoBulk>::IntoBulk
where
&'a mut Self: ~const IntoBulk
{
self.into_bulk()
}
}
impl<T> const AsBulk for T
where
T: ?Sized
{
}
pub const trait IntoBulk: IntoIterator<Item: Thin, IntoIter: ExactSizeIterator>
{
/// Which kind of bulk are we turning this into?
type IntoBulk: ~const Bulk<Item = Self::Item, IntoIter = Self::IntoIter>;
/// Creates a bulk from a value.
///
/// See the [crate documentation](crate) for more.
///
/// # Examples
///
/// ```
/// use bulks::*;
///
/// let v = [1, 2, 3];
/// let mut bulk = v.into_bulk();
/// let u: [_; _] = bulk.collect();
///
/// assert_eq!(u, [1, 2, 3]);
/// ```
fn into_bulk(self) -> Self::IntoBulk;
}
impl<T> const IntoBulk for T
where
Self: ~const Bulk
{
type IntoBulk = Self;
fn into_bulk(self) -> Self::IntoBulk
{
self
}
}