from_ascii/
base.rs

1/// A trait to abstract the idea of creating a new instance of a type from a
2/// ascii string.
3///
4/// It's a near clone of standard `FromStr` trait.
5pub trait FromAscii: Sized {
6    /// The associated error which can be returned from parsing.
7    type Err;
8
9    /// Parses a ascii string `s` to return a value of this type.
10    ///
11    /// If parsing succeeds, return the value inside `Ok`, otherwise
12    /// when the string is ill-formatted return an error specific to the
13    /// inside `Err`. The error type is specific to implementation of the trait.
14    ///
15    /// # Examples
16    ///
17    /// Basic usage with `i32`, a type that implements `FromAscii`:
18    ///
19    /// ```
20    /// use from_ascii::FromAscii;
21    ///
22    /// let s = b"5";
23    /// let x = i32::from_ascii(s).unwrap();
24    ///
25    /// assert_eq!(5, x);
26    /// ```
27    fn from_ascii(s: &[u8]) -> Result<Self, Self::Err>;
28}