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
//! A value given back by a list.
use fmt;
use LexicalError;
/// An operation of a [`LexicalList`](crate::LexicalList) that took ownership of a value failed: the error
/// and the value, given back unchanged.
///
/// [`push`](crate::LexicalList::push), [`unshift`](crate::LexicalList::unshift),
/// [`set`](crate::LexicalList::set) and [`set_untrusted`](crate::LexicalList::set_untrusted) move the values
/// into the list, so on failure they can't simply return an error: the values would be lost. `Rejected`
/// holds both. It converts into [`LexicalError`] and [`Error`](crate::Error) with `?` (dropping the value),
/// and [`into_value`](Self::into_value) gives the value back, for example to retry after
/// [`LexicalList::rebalance`](crate::LexicalList::rebalance).
///
/// # Example
///
/// ```
/// # use staquia::{Item, LexicalList, Position, Staquia};
/// # #[derive(Debug)]
/// # struct Task { id: u32, position: String }
/// # impl Item for Task {
/// # type Id = u32;
/// # fn id(&self) -> &u32 { &self.id }
/// # fn position(&self) -> &str { &self.position }
/// # fn set_position(&mut self, position: &Position) { self.position = position.to_string(); }
/// # }
/// # let task = |id| Task { id, position: String::new() };
/// use staquia::LexicalError;
///
/// let mut list = LexicalList::new(Staquia::create('!', 'a', 'z', 5, 15, 0.15)?);
/// list.push(task(1))?;
///
/// // The id 1 is already in the list: the task comes back
/// let rejected = list.push(task(1)).unwrap_err();
/// assert_eq!(rejected.error, LexicalError::DuplicateId(1));
/// assert_eq!(rejected.value.id, 1);
/// # Ok::<(), staquia::Error<u32>>(())
/// ```