pub trait FromStrSequential: Sized {
type Err;
// Required method
fn from_str_sequential(s: &str) -> Result<Self, Self::Err>;
}
Expand description
sibling trait of FromStr
. Used on enums with unit and un-named variants, and try to convert the string to each variant sequentially (from top to bottom variant). For unit variant,
the string must be the variant name (case-insentive). For un-named variants, the string must match the FromStr
implementation of the un-named type.
§Example
use from_str_sequential::FromStrSequential;
#[derive(Debug, FromStrSequential, PartialEq, Eq)]
enum Foo {
Bar,
Baz(usize),
}
assert_eq!(Foo::Bar, Foo::from_str_sequential("bar").unwrap());
assert_eq!(Foo::Bar, Foo::from_str_sequential("BaR").unwrap());
assert_eq!(Foo::Baz(100), Foo::from_str_sequential("100").unwrap());
Required Associated Types§
Required Methods§
fn from_str_sequential(s: &str) -> Result<Self, Self::Err>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.