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 From 8207a48a612fb6971e0b8fc8924c133e12b2ea36 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Fri, 15 Feb 2019 07:28:47 +0100 Subject: Added docstrings to SortingMethods enum --- src/listing.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/listing.rs') diff --git a/src/listing.rs b/src/listing.rs index 6d956ac..f82764e 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -10,6 +10,15 @@ use std::path::Path; arg_enum! { #[derive(Clone, Copy, Debug)] /// Available sorting methods + /// + /// Natural: natural sorting method + /// 1 -> 2 -> 3 -> 11 + /// + /// Alpha: pure alphabetical sorting method + /// 1 -> 11 -> 2 -> 3 + /// + /// DirsFirst: directories are listed first, alphabetical sorting is also applied + /// 1/ -> 2/ -> 3/ -> 11 -> 12 pub enum SortingMethods { Natural, Alpha, -- cgit v1.2.3 From 5c58453b698ec2925e1be7c885301a65e3a7af03 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Fri, 15 Feb 2019 19:02:57 +0100 Subject: Removed extern crate invokations --- src/listing.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/listing.rs') diff --git a/src/listing.rs b/src/listing.rs index f82764e..056c847 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -1,5 +1,6 @@ use actix_web::{fs, HttpRequest, HttpResponse, Result}; use bytesize::ByteSize; +use clap::{_clap_count_exprs, arg_enum}; use htmlescape::encode_minimal as escape_html_entity; use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use std::cmp::Ordering; -- cgit v1.2.3