Sfoglia il codice sorgente

use match for timeformat-parsing

Denis Cornehl 3 anni fa
parent
commit
1b54874ce8
2 ha cambiato i file con 9 aggiunte e 18 eliminazioni
  1. 1 1
      src/options/error.rs
  2. 8 17
      src/options/view.rs

+ 1 - 1
src/options/error.rs

@@ -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),

+ 8 - 17
src/options/view.rs

@@ -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()))
         }
     }
 }