1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use std::str::FromStr; const POSITIONAL: &str = "positional"; const NAMED: &str = "named"; const RAW: &str = "raw"; #[derive(Clone, Debug, PartialEq)] pub enum ParamStyle { Positional, Named, Raw, } impl Default for ParamStyle { fn default() -> Self { Self::Positional } } impl FromStr for ParamStyle { type Err = String; fn from_str(s: &str) -> Result<Self, String> { match s { POSITIONAL => Ok(Self::Positional), NAMED => Ok(Self::Named), RAW => Ok(Self::Raw), _ => Err(format!( "Invalid value for params key. Must be one of [{}, {}, {}]", POSITIONAL, NAMED, RAW )), } } }