-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
///
/// # Examples
///
- /// ```rust
+ /// ```
/// use std::collections::DList;
///
/// let mut a = DList::new();
/// Returns `true` if the `DList` is empty.
///
/// This operation should compute in O(1) time.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ /// assert!(dl.is_empty());
+ ///
+ /// dl.push_front("foo");
+ /// assert!(!dl.is_empty());
+ /// ```
#[inline]
#[stable]
pub fn is_empty(&self) -> bool {
/// Returns the length of the `DList`.
///
/// This operation should compute in O(1) time.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ ///
+ /// dl.push_front(2is);
+ /// assert_eq!(dl.len(), 1);
+ ///
+ /// dl.push_front(1);
+ /// assert_eq!(dl.len(), 2);
+ ///
+ /// dl.push_back(3);
+ /// assert_eq!(dl.len(), 3);
+ ///
+ /// ```
#[inline]
#[stable]
pub fn len(&self) -> uint {
/// Removes all elements from the `DList`.
///
/// This operation should compute in O(n) time.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ ///
+ /// dl.push_front(2is);
+ /// dl.push_front(1);
+ /// assert_eq!(dl.len(), 2);
+ /// assert_eq!(dl.front(), Some(&1is));
+ ///
+ /// dl.clear();
+ /// assert_eq!(dl.len(), 0);
+ /// assert_eq!(dl.front(), None);
+ ///
+ /// ```
#[inline]
#[stable]
pub fn clear(&mut self) {
/// Provides a reference to the front element, or `None` if the list is
/// empty.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ /// assert_eq!(dl.front(), None);
+ ///
+ /// dl.push_front(1);
+ /// assert_eq!(dl.front(), Some(&1is));
+ ///
+ /// ```
#[inline]
#[stable]
pub fn front(&self) -> Option<&T> {
/// Provides a mutable reference to the front element, or `None` if the list
/// is empty.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ /// assert_eq!(dl.front(), None);
+ ///
+ /// dl.push_front(1);
+ /// assert_eq!(dl.front(), Some(&1is));
+ ///
+ /// match dl.front_mut() {
+ /// None => {},
+ /// Some(x) => *x = 5is,
+ /// }
+ /// assert_eq!(dl.front(), Some(&5is));
+ ///
+ /// ```
#[inline]
#[stable]
pub fn front_mut(&mut self) -> Option<&mut T> {
/// Provides a reference to the back element, or `None` if the list is
/// empty.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ /// assert_eq!(dl.back(), None);
+ ///
+ /// dl.push_back(1);
+ /// assert_eq!(dl.back(), Some(&1is));
+ ///
+ /// ```
#[inline]
#[stable]
pub fn back(&self) -> Option<&T> {
/// Provides a mutable reference to the back element, or `None` if the list
/// is empty.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ /// assert_eq!(dl.back(), None);
+ ///
+ /// dl.push_back(1);
+ /// assert_eq!(dl.back(), Some(&1is));
+ ///
+ /// match dl.back_mut() {
+ /// None => {},
+ /// Some(x) => *x = 5is,
+ /// }
+ /// assert_eq!(dl.back(), Some(&5is));
+ ///
+ /// ```
#[inline]
#[stable]
pub fn back_mut(&mut self) -> Option<&mut T> {
/// Adds an element first in the list.
///
/// This operation should compute in O(1) time.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut dl = DList::new();
+ ///
+ /// dl.push_front(2is);
+ /// assert_eq!(dl.front().unwrap(), &2is);
+ ///
+ /// dl.push_front(1);
+ /// assert_eq!(dl.front().unwrap(), &1);
+ ///
+ /// ```
#[stable]
pub fn push_front(&mut self, elt: T) {
self.push_front_node(box Node::new(elt))
/// empty.
///
/// This operation should compute in O(1) time.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut d = DList::new();
+ /// assert_eq!(d.pop_front(), None);
+ ///
+ /// d.push_front(1is);
+ /// d.push_front(3);
+ /// assert_eq!(d.pop_front(), Some(3));
+ /// assert_eq!(d.pop_front(), Some(1));
+ /// assert_eq!(d.pop_front(), None);
+ ///
+ /// ```
+ ///
#[stable]
pub fn pop_front(&mut self) -> Option<T> {
self.pop_front_node().map(|box Node{value, ..}| value)
///
/// # Examples
///
- /// ```rust
+ /// ```
/// use std::collections::DList;
///
/// let mut d = DList::new();
///
/// # Examples
///
- /// ```rust
+ /// ```
/// use std::collections::DList;
///
/// let mut d = DList::new();
/// including the index.
///
/// This operation should compute in O(n) time.
+ /// # Examples
+ ///
+ /// ```
+ /// use std::collections::DList;
+ ///
+ /// let mut d = DList::new();
+ ///
+ /// d.push_front(1is);
+ /// d.push_front(2);
+ /// d.push_front(3);
+ ///
+ /// let mut splitted = d.split_off(2);
+ ///
+ /// assert_eq!(splitted.pop_front(), Some(1));
+ /// assert_eq!(splitted.pop_front(), None);
+ /// ```
#[stable]
pub fn split_off(&mut self, at: uint) -> DList<T> {
let len = self.len();
///
/// # Examples
///
- /// ```rust
+ /// ```
/// use std::collections::DList;
///
/// let mut list: DList<int> = vec![1, 3, 4].into_iter().collect();
///
/// # Examples
///
- /// ```rust
+ /// ```
/// use std::collections::DList;
///
/// let mut list: DList<int> = vec![1, 2, 3].into_iter().collect();