@@ -66,13 +66,13 @@ fn remove_replace<T, P, F>(list: &mut LinkedList<T>, p: P, f: F)
66
66
let mut cursor = list . cursor_mut ();
67
67
// move to the first element, if it exists
68
68
loop {
69
- let should_replace = match cursor . peek () {
69
+ let should_replace = match cursor . peek_next () {
70
70
Some (element ) => p (element ),
71
71
None => break ,
72
72
};
73
73
if should_replace {
74
74
let old_element = cursor . pop (). unwrap ();
75
- cursor . insert (f (old_element ));
75
+ cursor . insert_after (f (old_element ));
76
76
}
77
77
cursor . move_next ();
78
78
}
@@ -108,7 +108,7 @@ fn main() {
108
108
}
109
109
cursor . move_next ();
110
110
}
111
- cursor . insert (12 );
111
+ cursor . insert_after (12 );
112
112
}
113
113
```
114
114
In general, the cursor interface is not the easiest way to do something.
@@ -142,9 +142,9 @@ impl<'list, T> Cursor<'list, T> {
142
142
/// Get the current element
143
143
pub fn current (& self ) -> Option <& 'list T >;
144
144
/// Get the following element
145
- pub fn peek (& self ) -> Option <& 'list T >;
145
+ pub fn peek_next (& self ) -> Option <& 'list T >;
146
146
/// Get the previous element
147
- pub fn peek_before (& self ) -> Option <& 'list T >;
147
+ pub fn peek_prev (& self ) -> Option <& 'list T >;
148
148
}
149
149
150
150
impl <'list T > CursorMut <'list , T > {
@@ -157,17 +157,17 @@ impl<'list T> CursorMut<'list, T> {
157
157
/// Get the current element
158
158
pub fn current (& mut self ) -> Option <& mut T >;
159
159
/// Get the next element
160
- pub fn peek (& mut self ) -> Option <& mut T >;
160
+ pub fn peek_next (& mut self ) -> Option <& mut T >;
161
161
/// Get the previous element
162
- pub fn peek_before (& mut self ) -> Option <& mut T >;
162
+ pub fn peek_prev (& mut self ) -> Option <& mut T >;
163
163
164
164
/// Get an immutable cursor at the current element
165
165
pub fn as_cursor <'cm >(& 'cm self ) -> Cursor <'cm , T >;
166
166
167
167
// Now the list editing operations
168
168
169
169
/// Insert `item` after the cursor
170
- pub fn insert (& mut self , item : T );
170
+ pub fn insert_after (& mut self , item : T );
171
171
/// Insert `item` before the cursor
172
172
pub fn insert_before (& mut self , item : T );
173
173
@@ -177,15 +177,15 @@ impl<'list T> CursorMut<'list, T> {
177
177
pub fn pop_before (& mut self ) -> Option <T >;
178
178
179
179
/// Insert `list` between the current element and the next
180
- pub fn insert_list (& mut self , list : LinkedList <T >);
180
+ pub fn splice_after (& mut self , list : LinkedList <T >);
181
181
/// Insert `list` between the previous element and current
182
- pub fn insert_list_before (& mut self , list : LinkedList <T >);
182
+ pub fn splice_before (& mut self , list : LinkedList <T >);
183
183
184
184
/// Split the list in two after the current element
185
185
/// The returned list consists of all elements following the current one.
186
186
// note: consuming the cursor is not necessary here, but it makes sense
187
187
// given the interface
188
- pub fn split (self ) -> LinkedList <T >;
188
+ pub fn split_after (self ) -> LinkedList <T >;
189
189
/// Split the list in two before the current element
190
190
pub fn split_before (self ) -> LinkedList <T >;
191
191
}
@@ -195,17 +195,17 @@ One should closely consider the lifetimes in this interface. Both `Cursor` and
195
195
the annotation of ` 'list ` .
196
196
197
197
The lifetime elision for their constructors is correct as
198
- ```
198
+ ``` rust
199
199
pub fn cursor (& self ) -> Cursor <T >
200
200
```
201
201
becomes
202
- ```
202
+ ```rust
203
203
pub fn cursor <'list >(& 'list self ) -> Cursor <'list , T >
204
204
```
205
205
which is what we would expect . (the same goes for `CursorMut `).
206
206
207
- Since ` Cursor ` cannot mutate its list, ` current ` , ` peek ` and ` peek_before ` all
208
- live as long as ` 'list ` . However, in ` CursorMut ` we must be careful to make
207
+ Since `Cursor ` cannot mutate its list , `current `, `peek_next ` and `peek_prev `
208
+ all live as long as `'list `. However , in `CursorMut ` we must be careful to make
209
209
these methods borrow . Otherwise , one could produce multiple mutable references
210
210
to the same element .
211
211
0 commit comments