from-str-sequential 0.1.0

A FromStr-like trait for enums, matching the first compatible variant
Documentation
  • Coverage
  • 50%
    2 out of 4 items documented2 out of 3 items with examples
  • Size
  • Source code size: 39.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.08 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kraktus/from-str-sequential
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kraktus

from-str-sequential

crates.io docs.rs

A utility crate which implement a simple FromStrSequential trait similar to 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.

This crate was initially released to allow multiple input formats for clap::Command

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());