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
// TODO: next_slice()
/// Lending queue consumer trait.
///
/// LendingReader returns `&T` with `&mut self` lifetime. This means you should deal
/// with message BEFORE consuming the next one.
/// Because of this, it does not implement [Iterator]. But [ClonedReader] does.
///
/// We expect it to be mainly used in this way:
/// ```
/// # let queue: chute::spmc::Queue<usize> = Default::default();
/// # let mut reader = queue.reader();
/// # use chute::LendingReader;
/// while let Some(value) = reader.next() {
/// // Do something
/// }
/// ```
///
/// # Design choices
///
/// The value returned by the reader lives as long as the block where it is stored.
/// From the reader's point of view, we can guarantee that the value remains valid
/// as long as the block does not change. However, in Rust, we cannot make such
/// granular guarantees. Instead, we guarantee that the value remains valid until the
/// reader is mutated. This means the value is guaranteed to live until the next
/// read operation, at which point the block may change, and the old block could
/// be destructed.
/// Cloning queue consumer.
///
/// Reader that clones `T` upon return. Implements [Iterator].
///
/// Constructed by [LendingReader::cloned()].