use match for timeformat-parsing

This commit is contained in:
Denis Cornehl 2022-04-30 19:59:38 +02:00
parent 4911ac6714
commit 1b54874ce8
2 changed files with 9 additions and 18 deletions

View File

@ -14,7 +14,7 @@ pub enum OptionsError {
Parse(ParseError),
/// The user supplied an illegal choice to an Argument.
BadArgument(&'static Arg, OsString),
BadArgument(&'static Arg, String),
/// The user supplied a set of options that are unsupported
Unsupported(String),

View File

@ -254,23 +254,14 @@ impl TimeFormat {
}
};
if &word == "default" {
Ok(Self::DefaultFormat)
}
else if &word == "relative" {
Ok(Self::Relative)
}
else if &word == "iso" {
Ok(Self::ISOFormat)
}
else if &word == "long-iso" {
Ok(Self::LongISO)
}
else if &word == "full-iso" {
Ok(Self::FullISO)
}
else {
Err(OptionsError::BadArgument(&flags::TIME_STYLE, word))
let word = word.to_string_lossy();
match word.as_ref() {
"default" => Ok(Self::DefaultFormat),
"relative" => Ok(Self::Relative),
"iso" => Ok(Self::ISOFormat),
"long-iso" => Ok(Self::LongISO),
"full-iso" => Ok(Self::FullISO),
_ => Err(OptionsError::BadArgument(&flags::TIME_STYLE, word.to_string()))
}
}
}