Explorar o código

Add doc example for `num_traits::Num::from_str_radix`.

Corey Farwell %!s(int64=8) %!d(string=hai) anos
pai
achega
19109883de
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      traits/src/lib.rs

+ 12 - 0
traits/src/lib.rs

@@ -43,6 +43,18 @@ pub trait Num: PartialEq + Zero + One
     type FromStrRadixErr;
 
     /// Convert from a string and radix <= 36.
+    ///
+    /// # Examples
+    ///
+    /// ```rust
+    /// use num_traits::Num;
+    ///
+    /// let result = <i32 as Num>::from_str_radix("27", 10);
+    /// assert_eq!(result, Ok(27));
+    ///
+    /// let result = <i32 as Num>::from_str_radix("foo", 10);
+    /// assert!(result.is_err());
+    /// ```
     fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>;
 }