From fb63c8de43c538bcaf9afd57122fbf1c542966d0 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Thu, 14 Feb 2019 22:24:07 +0100 Subject: Switched to structopt --- src/listing.rs | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/listing.rs') diff --git a/src/listing.rs b/src/listing.rs index f0662ef..6d956ac 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -6,26 +6,19 @@ use std::cmp::Ordering; use std::fmt::Write as FmtWrite; use std::io; use std::path::Path; -use std::str::FromStr; -#[derive(Clone, Copy, Debug)] -/// Available sorting methods -pub enum SortingMethods { - /// Natural sorting method - /// 1 -> 2 -> 3 -> 11 - Natural, - - /// Pure alphabetical sorting method - /// 1 -> 11 -> 2 -> 3 - Alpha, - - /// Directories are listed first, alphabetical sorting is also applied - /// 1/ -> 2/ -> 3/ -> 11 -> 12 - DirsFirst, +arg_enum! { + #[derive(Clone, Copy, Debug)] + /// Available sorting methods + pub enum SortingMethods { + Natural, + Alpha, + DirsFirst, + } } #[derive(PartialEq)] -/// Possible entry types +/// Possible entry types enum EntryType { /// Entry is a directory Directory, @@ -75,19 +68,6 @@ impl Entry { } } -impl FromStr for SortingMethods { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "natural" => Ok(SortingMethods::Natural), - "alpha" => Ok(SortingMethods::Alpha), - "dirsfirst" => Ok(SortingMethods::DirsFirst), - _ => Err(()), - } - } -} - pub fn file_handler(req: &HttpRequest) -> Result { let path = &req.state().path; Ok(fs::NamedFile::open(path)?) -- cgit v1.2.3