Skip to content

Commit f459e80

Browse files
committed
Rewrite collections::LinkedList::append doc example.
1 parent d1df3fe commit f459e80

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/libcollections/linked_list.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,22 @@ impl<T> LinkedList<T> {
203203
/// ```
204204
/// use std::collections::LinkedList;
205205
///
206-
/// let mut a = LinkedList::new();
207-
/// let mut b = LinkedList::new();
208-
/// a.push_back(1);
209-
/// a.push_back(2);
210-
/// b.push_back(3);
211-
/// b.push_back(4);
206+
/// let mut list1 = LinkedList::new();
207+
/// list1.push_back('a');
212208
///
213-
/// a.append(&mut b);
209+
/// let mut list2 = LinkedList::new();
210+
/// list2.push_back('b');
211+
/// list2.push_back('c');
214212
///
215-
/// for e in &a {
216-
/// println!("{}", e); // prints 1, then 2, then 3, then 4
217-
/// }
218-
/// println!("{}", b.len()); // prints 0
213+
/// list1.append(&mut list2);
214+
///
215+
/// let mut iter = list1.iter();
216+
/// assert_eq!(iter.next(), Some(&'a'));
217+
/// assert_eq!(iter.next(), Some(&'b'));
218+
/// assert_eq!(iter.next(), Some(&'c'));
219+
/// assert!(iter.next().is_none());
220+
///
221+
/// assert!(list2.is_empty());
219222
/// ```
220223
#[stable(feature = "rust1", since = "1.0.0")]
221224
pub fn append(&mut self, other: &mut Self) {

0 commit comments

Comments
 (0)