From 41729b83bc3bf93cfb9cf727b64f5c3a2b35cefe Mon Sep 17 00:00:00 2001 From: Jonas Hietala Date: Sat, 19 Jul 2014 12:10:09 +0200 Subject: Document some trait methods. --- src/libcore/collections.rs | 14 ++++++++++++++ src/libcore/default.rs | 10 ++++++++++ 2 files changed, 24 insertions(+) (limited to 'src/libcore') 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, f64) = Default::default(); + /// let (a, b, (c, d)): (int, uint, (bool, bool)) = Default::default(); + /// ``` fn default() -> Self; } -- cgit 1.4.1-3-g733a5