@@ -172,6 +172,14 @@ impl<T> Default for LinkedList<T> {
172
172
173
173
impl < T > LinkedList < T > {
174
174
/// Creates an empty `LinkedList`.
175
+ ///
176
+ /// # Examples
177
+ ///
178
+ /// ```
179
+ /// use std::collections::LinkedList;
180
+ ///
181
+ /// let list: LinkedList<u32> = LinkedList::new();
182
+ /// ```
175
183
#[ inline]
176
184
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
177
185
pub fn new ( ) -> Self {
@@ -226,6 +234,24 @@ impl<T> LinkedList<T> {
226
234
}
227
235
228
236
/// Provides a forward iterator.
237
+ ///
238
+ /// # Examples
239
+ ///
240
+ /// ```
241
+ /// use std::collections::LinkedList;
242
+ ///
243
+ /// let mut list: LinkedList<u32> = LinkedList::new();
244
+ ///
245
+ /// list.push_back(0);
246
+ /// list.push_back(1);
247
+ /// list.push_back(2);
248
+ ///
249
+ /// let mut iter = list.iter();
250
+ /// assert_eq!(iter.next(), Some(&0));
251
+ /// assert_eq!(iter.next(), Some(&1));
252
+ /// assert_eq!(iter.next(), Some(&2));
253
+ /// assert_eq!(iter.next(), None);
254
+ /// ```
229
255
#[ inline]
230
256
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
231
257
pub fn iter ( & self ) -> Iter < T > {
@@ -238,6 +264,28 @@ impl<T> LinkedList<T> {
238
264
}
239
265
240
266
/// Provides a forward iterator with mutable references.
267
+ ///
268
+ /// # Examples
269
+ ///
270
+ /// ```
271
+ /// use std::collections::LinkedList;
272
+ ///
273
+ /// let mut list: LinkedList<u32> = LinkedList::new();
274
+ ///
275
+ /// list.push_back(0);
276
+ /// list.push_back(1);
277
+ /// list.push_back(2);
278
+ ///
279
+ /// for element in list.iter_mut() {
280
+ /// *element += 10;
281
+ /// }
282
+ ///
283
+ /// let mut iter = list.iter();
284
+ /// assert_eq!(iter.next(), Some(&10));
285
+ /// assert_eq!(iter.next(), Some(&11));
286
+ /// assert_eq!(iter.next(), Some(&12));
287
+ /// assert_eq!(iter.next(), None);
288
+ /// ```
241
289
#[ inline]
242
290
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
243
291
pub fn iter_mut ( & mut self ) -> IterMut < T > {
@@ -289,7 +337,6 @@ impl<T> LinkedList<T> {
289
337
///
290
338
/// dl.push_back(3);
291
339
/// assert_eq!(dl.len(), 3);
292
- ///
293
340
/// ```
294
341
#[ inline]
295
342
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -316,7 +363,6 @@ impl<T> LinkedList<T> {
316
363
/// dl.clear();
317
364
/// assert_eq!(dl.len(), 0);
318
365
/// assert_eq!(dl.front(), None);
319
- ///
320
366
/// ```
321
367
#[ inline]
322
368
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -326,6 +372,23 @@ impl<T> LinkedList<T> {
326
372
327
373
/// Returns `true` if the `LinkedList` contains an element equal to the
328
374
/// given value.
375
+ ///
376
+ /// # Examples
377
+ ///
378
+ /// ```
379
+ /// #![feature(linked_list_contains)]
380
+ ///
381
+ /// use std::collections::LinkedList;
382
+ ///
383
+ /// let mut list: LinkedList<u32> = LinkedList::new();
384
+ ///
385
+ /// list.push_back(0);
386
+ /// list.push_back(1);
387
+ /// list.push_back(2);
388
+ ///
389
+ /// assert_eq!(list.contains(&0), true);
390
+ /// assert_eq!(list.contains(&10), false);
391
+ /// ```
329
392
#[ unstable( feature = "linked_list_contains" , reason = "recently added" ,
330
393
issue = "32630" ) ]
331
394
pub fn contains ( & self , x : & T ) -> bool
@@ -347,7 +410,6 @@ impl<T> LinkedList<T> {
347
410
///
348
411
/// dl.push_front(1);
349
412
/// assert_eq!(dl.front(), Some(&1));
350
- ///
351
413
/// ```
352
414
#[ inline]
353
415
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -374,7 +436,6 @@ impl<T> LinkedList<T> {
374
436
/// Some(x) => *x = 5,
375
437
/// }
376
438
/// assert_eq!(dl.front(), Some(&5));
377
- ///
378
439
/// ```
379
440
#[ inline]
380
441
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -395,7 +456,6 @@ impl<T> LinkedList<T> {
395
456
///
396
457
/// dl.push_back(1);
397
458
/// assert_eq!(dl.back(), Some(&1));
398
- ///
399
459
/// ```
400
460
#[ inline]
401
461
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -422,7 +482,6 @@ impl<T> LinkedList<T> {
422
482
/// Some(x) => *x = 5,
423
483
/// }
424
484
/// assert_eq!(dl.back(), Some(&5));
425
- ///
426
485
/// ```
427
486
#[ inline]
428
487
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -446,7 +505,6 @@ impl<T> LinkedList<T> {
446
505
///
447
506
/// dl.push_front(1);
448
507
/// assert_eq!(dl.front().unwrap(), &1);
449
- ///
450
508
/// ```
451
509
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
452
510
pub fn push_front ( & mut self , elt : T ) {
@@ -471,9 +529,7 @@ impl<T> LinkedList<T> {
471
529
/// assert_eq!(d.pop_front(), Some(3));
472
530
/// assert_eq!(d.pop_front(), Some(1));
473
531
/// assert_eq!(d.pop_front(), None);
474
- ///
475
532
/// ```
476
- ///
477
533
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
478
534
pub fn pop_front ( & mut self ) -> Option < T > {
479
535
self . pop_front_node ( ) . map ( Node :: into_element)
0 commit comments