1
- // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -230,7 +230,7 @@ impl<T> DList<T> {
230
230
///
231
231
/// # Examples
232
232
///
233
- /// ```rust
233
+ /// ```
234
234
/// use std::collections::DList;
235
235
///
236
236
/// let mut a = DList::new();
@@ -304,6 +304,18 @@ impl<T> DList<T> {
304
304
/// Returns `true` if the `DList` is empty.
305
305
///
306
306
/// This operation should compute in O(1) time.
307
+ ///
308
+ /// # Examples
309
+ ///
310
+ /// ```
311
+ /// use std::collections::DList;
312
+ ///
313
+ /// let mut dl = DList::new();
314
+ /// assert!(dl.is_empty());
315
+ ///
316
+ /// dl.push_front("foo");
317
+ /// assert!(!dl.is_empty());
318
+ /// ```
307
319
#[ inline]
308
320
#[ stable]
309
321
pub fn is_empty ( & self ) -> bool {
@@ -313,6 +325,24 @@ impl<T> DList<T> {
313
325
/// Returns the length of the `DList`.
314
326
///
315
327
/// This operation should compute in O(1) time.
328
+ ///
329
+ /// # Examples
330
+ ///
331
+ /// ```
332
+ /// use std::collections::DList;
333
+ ///
334
+ /// let mut dl = DList::new();
335
+ ///
336
+ /// dl.push_front(2is);
337
+ /// assert_eq!(dl.len(), 1);
338
+ ///
339
+ /// dl.push_front(1);
340
+ /// assert_eq!(dl.len(), 2);
341
+ ///
342
+ /// dl.push_back(3);
343
+ /// assert_eq!(dl.len(), 3);
344
+ ///
345
+ /// ```
316
346
#[ inline]
317
347
#[ stable]
318
348
pub fn len ( & self ) -> uint {
@@ -322,6 +352,24 @@ impl<T> DList<T> {
322
352
/// Removes all elements from the `DList`.
323
353
///
324
354
/// This operation should compute in O(n) time.
355
+ ///
356
+ /// # Examples
357
+ ///
358
+ /// ```
359
+ /// use std::collections::DList;
360
+ ///
361
+ /// let mut dl = DList::new();
362
+ ///
363
+ /// dl.push_front(2is);
364
+ /// dl.push_front(1);
365
+ /// assert_eq!(dl.len(), 2);
366
+ /// assert_eq!(dl.front(), Some(&1is));
367
+ ///
368
+ /// dl.clear();
369
+ /// assert_eq!(dl.len(), 0);
370
+ /// assert_eq!(dl.front(), None);
371
+ ///
372
+ /// ```
325
373
#[ inline]
326
374
#[ stable]
327
375
pub fn clear ( & mut self ) {
@@ -330,6 +378,19 @@ impl<T> DList<T> {
330
378
331
379
/// Provides a reference to the front element, or `None` if the list is
332
380
/// empty.
381
+ ///
382
+ /// # Examples
383
+ ///
384
+ /// ```
385
+ /// use std::collections::DList;
386
+ ///
387
+ /// let mut dl = DList::new();
388
+ /// assert_eq!(dl.front(), None);
389
+ ///
390
+ /// dl.push_front(1);
391
+ /// assert_eq!(dl.front(), Some(&1is));
392
+ ///
393
+ /// ```
333
394
#[ inline]
334
395
#[ stable]
335
396
pub fn front ( & self ) -> Option < & T > {
@@ -338,6 +399,25 @@ impl<T> DList<T> {
338
399
339
400
/// Provides a mutable reference to the front element, or `None` if the list
340
401
/// is empty.
402
+ ///
403
+ /// # Examples
404
+ ///
405
+ /// ```
406
+ /// use std::collections::DList;
407
+ ///
408
+ /// let mut dl = DList::new();
409
+ /// assert_eq!(dl.front(), None);
410
+ ///
411
+ /// dl.push_front(1);
412
+ /// assert_eq!(dl.front(), Some(&1is));
413
+ ///
414
+ /// match dl.front_mut() {
415
+ /// None => {},
416
+ /// Some(x) => *x = 5is,
417
+ /// }
418
+ /// assert_eq!(dl.front(), Some(&5is));
419
+ ///
420
+ /// ```
341
421
#[ inline]
342
422
#[ stable]
343
423
pub fn front_mut ( & mut self ) -> Option < & mut T > {
@@ -346,6 +426,19 @@ impl<T> DList<T> {
346
426
347
427
/// Provides a reference to the back element, or `None` if the list is
348
428
/// empty.
429
+ ///
430
+ /// # Examples
431
+ ///
432
+ /// ```
433
+ /// use std::collections::DList;
434
+ ///
435
+ /// let mut dl = DList::new();
436
+ /// assert_eq!(dl.back(), None);
437
+ ///
438
+ /// dl.push_back(1);
439
+ /// assert_eq!(dl.back(), Some(&1is));
440
+ ///
441
+ /// ```
349
442
#[ inline]
350
443
#[ stable]
351
444
pub fn back ( & self ) -> Option < & T > {
@@ -354,6 +447,25 @@ impl<T> DList<T> {
354
447
355
448
/// Provides a mutable reference to the back element, or `None` if the list
356
449
/// is empty.
450
+ ///
451
+ /// # Examples
452
+ ///
453
+ /// ```
454
+ /// use std::collections::DList;
455
+ ///
456
+ /// let mut dl = DList::new();
457
+ /// assert_eq!(dl.back(), None);
458
+ ///
459
+ /// dl.push_back(1);
460
+ /// assert_eq!(dl.back(), Some(&1is));
461
+ ///
462
+ /// match dl.back_mut() {
463
+ /// None => {},
464
+ /// Some(x) => *x = 5is,
465
+ /// }
466
+ /// assert_eq!(dl.back(), Some(&5is));
467
+ ///
468
+ /// ```
357
469
#[ inline]
358
470
#[ stable]
359
471
pub fn back_mut ( & mut self ) -> Option < & mut T > {
@@ -363,6 +475,21 @@ impl<T> DList<T> {
363
475
/// Adds an element first in the list.
364
476
///
365
477
/// This operation should compute in O(1) time.
478
+ ///
479
+ /// # Examples
480
+ ///
481
+ /// ```
482
+ /// use std::collections::DList;
483
+ ///
484
+ /// let mut dl = DList::new();
485
+ ///
486
+ /// dl.push_front(2is);
487
+ /// assert_eq!(dl.front().unwrap(), &2is);
488
+ ///
489
+ /// dl.push_front(1);
490
+ /// assert_eq!(dl.front().unwrap(), &1);
491
+ ///
492
+ /// ```
366
493
#[ stable]
367
494
pub fn push_front ( & mut self , elt : T ) {
368
495
self . push_front_node ( box Node :: new ( elt) )
@@ -372,6 +499,23 @@ impl<T> DList<T> {
372
499
/// empty.
373
500
///
374
501
/// This operation should compute in O(1) time.
502
+ ///
503
+ /// # Examples
504
+ ///
505
+ /// ```
506
+ /// use std::collections::DList;
507
+ ///
508
+ /// let mut d = DList::new();
509
+ /// assert_eq!(d.pop_front(), None);
510
+ ///
511
+ /// d.push_front(1is);
512
+ /// d.push_front(3);
513
+ /// assert_eq!(d.pop_front(), Some(3));
514
+ /// assert_eq!(d.pop_front(), Some(1));
515
+ /// assert_eq!(d.pop_front(), None);
516
+ ///
517
+ /// ```
518
+ ///
375
519
#[ stable]
376
520
pub fn pop_front ( & mut self ) -> Option < T > {
377
521
self . pop_front_node ( ) . map ( |box Node { value, ..} | value)
@@ -381,7 +525,7 @@ impl<T> DList<T> {
381
525
///
382
526
/// # Examples
383
527
///
384
- /// ```rust
528
+ /// ```
385
529
/// use std::collections::DList;
386
530
///
387
531
/// let mut d = DList::new();
@@ -399,7 +543,7 @@ impl<T> DList<T> {
399
543
///
400
544
/// # Examples
401
545
///
402
- /// ```rust
546
+ /// ```
403
547
/// use std::collections::DList;
404
548
///
405
549
/// let mut d = DList::new();
@@ -417,6 +561,22 @@ impl<T> DList<T> {
417
561
/// including the index.
418
562
///
419
563
/// This operation should compute in O(n) time.
564
+ /// # Examples
565
+ ///
566
+ /// ```
567
+ /// use std::collections::DList;
568
+ ///
569
+ /// let mut d = DList::new();
570
+ ///
571
+ /// d.push_front(1is);
572
+ /// d.push_front(2);
573
+ /// d.push_front(3);
574
+ ///
575
+ /// let mut splitted = d.split_off(2);
576
+ ///
577
+ /// assert_eq!(splitted.pop_front(), Some(1));
578
+ /// assert_eq!(splitted.pop_front(), None);
579
+ /// ```
420
580
#[ stable]
421
581
pub fn split_off ( & mut self , at : uint ) -> DList < T > {
422
582
let len = self . len ( ) ;
@@ -593,7 +753,7 @@ impl<'a, A> IterMut<'a, A> {
593
753
///
594
754
/// # Examples
595
755
///
596
- /// ```rust
756
+ /// ```
597
757
/// use std::collections::DList;
598
758
///
599
759
/// let mut list: DList<int> = vec![1, 3, 4].into_iter().collect();
@@ -619,7 +779,7 @@ impl<'a, A> IterMut<'a, A> {
619
779
///
620
780
/// # Examples
621
781
///
622
- /// ```rust
782
+ /// ```
623
783
/// use std::collections::DList;
624
784
///
625
785
/// let mut list: DList<int> = vec![1, 2, 3].into_iter().collect();
0 commit comments