diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/collections.rs | 14 | ||||
| -rw-r--r-- | src/libcore/default.rs | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/collections.rs b/src/libcore/collections.rs index 0bb9289397a..7d87e03c134 100644 --- a/src/libcore/collections.rs +++ b/src/libcore/collections.rs @@ -14,9 +14,23 @@ /// knowledge known is the number of elements contained within. pub trait Collection { /// Return the number of elements in the container + /// + /// # Example + /// + /// ``` + /// let a = [1i, 2, 3]; + /// assert_eq!(a.len(), 3); + /// ``` fn len(&self) -> uint; /// Return true if the container contains no elements + /// + /// # Example + /// + /// ``` + /// let s = String::new(); + /// assert!(s.is_empty()); + /// ``` #[inline] fn is_empty(&self) -> bool { self.len() == 0 diff --git a/src/libcore/default.rs b/src/libcore/default.rs index 0fcc02aae0d..363d8ecf002 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -13,6 +13,16 @@ /// A trait that types which have a useful default value should implement. pub trait Default { /// Return the "default value" for a type. + /// + /// # Example + /// + /// ``` + /// use std::default::Default; + /// + /// let i: i8 = Default::default(); + /// let (x, y): (Option<String>, f64) = Default::default(); + /// let (a, b, (c, d)): (int, uint, (bool, bool)) = Default::default(); + /// ``` fn default() -> Self; } |
