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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use core::{pin::Pin, ptr::Thin};
use crate::{Bulk, Pinned};
pub const trait AsBulk<'a>: 'a
{
type Elem: 'a;
type AsBulk: Bulk<Item = &'a Self::Elem> + 'a;
/// 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 self) -> Self::AsBulk;
fn bulk_pin(self: Pin<&'a Self>) -> Pinned<Self::AsBulk>
{
unsafe {
Pinned::new_unchecked(
Pin::into_inner_unchecked(self)
.bulk()
)
}
}
}
pub const trait AsBulkMut<'a>: AsBulk<'a>
{
type AsBulkMut: Bulk<Item = &'a mut Self::Elem> + 'a;
/// 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 mut self) -> Self::AsBulkMut;
fn bulk_pin_mut(self: Pin<&'a mut Self>) -> Pinned<Self::AsBulkMut>
{
unsafe {
Pinned::new_unchecked(
Pin::into_inner_unchecked(self)
.bulk_mut()
)
}
}
}
const impl<'a, B, T> AsBulk<'a> for B
where
B: ?Sized + 'a,
T: 'a,
&'a B: [const] IntoBulk<Item = &'a T>
{
type AsBulk = <&'a B as IntoBulk>::IntoBulk;
type Elem = T;
fn bulk(&'a self) -> Self::AsBulk
{
self.into_bulk()
}
}
const impl<'a, B, T> AsBulkMut<'a> for B
where
B: ?Sized + 'a,
T: 'a,
&'a B: [const] IntoBulk<Item = &'a T>,
&'a mut B: [const] IntoBulk<Item = &'a mut T>
{
type AsBulkMut = <&'a mut B as IntoBulk>::IntoBulk;
fn bulk_mut(&'a mut self) -> Self::AsBulkMut
{
self.into_bulk()
}
}
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;
}
const impl<T> IntoBulk for T
where
Self: [const] Bulk
{
type IntoBulk = Self;
fn into_bulk(self) -> Self::IntoBulk
{
self
}
}