]> git.lizzy.rs Git - rust.git/commitdiff
Add some docs for FromString::from_str
authorSteve Klabnik <steve@steveklabnik.com>
Wed, 30 Sep 2015 21:42:41 +0000 (17:42 -0400)
committerSteve Klabnik <steve@steveklabnik.com>
Wed, 30 Sep 2015 21:42:41 +0000 (17:42 -0400)
@marchelzo pointed out on IRC that this doesn't have docs, so, let's
change that.

src/libcore/str/mod.rs

index 3c7f1b3688398fd64f904fd55d620de37fbe9e65..be2186945d563b2a31d1babdbac9628e925761ce 100644 (file)
@@ -48,6 +48,21 @@ pub trait FromStr: Sized {
     /// If parsing succeeds, return the value inside `Ok`, otherwise
     /// when the string is ill-formatted return an error specific to the
     /// inside `Err`. The error type is specific to implementation of the trait.
+    ///
+    /// # Examples
+    ///
+    /// Basic usage with [`i32`][ithirtytwo], a type that implements `FromStr`:
+    ///
+    /// [ithirtytwo]: ../primitive.i32.html
+    ///
+    /// ```
+    /// use std::str::FromStr;
+    ///
+    /// let s = "5";
+    /// let x = i32::from_str(s).unwrap();
+    ///
+    /// assert_eq!(5, x);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     fn from_str(s: &str) -> Result<Self, Self::Err>;
 }