fastobo/parser/
from_slice.rs

1use std::str::FromStr;
2
3/// Parse a value from a slice with a lifetime parameter.
4///
5/// This trait is an extension of the `FromStr` trait from the standard library,
6/// and allows keeping a reference to the slice passed as argument.
7pub trait FromSlice<'i>: Sized {
8    /// The associated error which can be returned from parsing.
9    type Err;
10    /// Parses a string slice `s` to return a value of this type.
11    fn from_slice(s: &'i str) -> Result<Self, Self::Err>;
12}
13
14impl<'i, T> FromSlice<'i> for T
15where
16    T: FromStr,
17{
18    type Err = <Self as FromStr>::Err;
19    fn from_slice(s: &'i str) -> Result<Self, Self::Err> {
20        <Self as FromStr>::from_str(s)
21    }
22}