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

This commit is contained in:
Corey Farwell 2017-01-30 23:42:27 -05:00 committed by GitHub
parent 74f1e26f62
commit 19109883de
1 changed files with 12 additions and 0 deletions

View File

@ -43,6 +43,18 @@ pub trait Num: PartialEq + Zero + One
type FromStrRadixErr; type FromStrRadixErr;
/// Convert from a string and radix <= 36. /// 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>; fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>;
} }