diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/dir.rs | 20 | ||||
-rw-r--r-- | src/fs/dir_action.rs | 6 | ||||
-rw-r--r-- | src/fs/feature/git.rs | 8 | ||||
-rw-r--r-- | src/fs/feature/xattr.rs | 4 | ||||
-rw-r--r-- | src/fs/fields.rs | 6 | ||||
-rw-r--r-- | src/fs/filter.rs | 46 | ||||
-rw-r--r-- | src/options/dir_action.rs | 14 | ||||
-rw-r--r-- | src/options/filter.rs | 60 | ||||
-rw-r--r-- | src/options/help.rs | 4 | ||||
-rw-r--r-- | src/options/misfire.rs | 12 | ||||
-rw-r--r-- | src/options/mod.rs | 8 | ||||
-rw-r--r-- | src/options/parser.rs | 8 | ||||
-rw-r--r-- | src/options/style.rs | 24 | ||||
-rw-r--r-- | src/options/version.rs | 4 | ||||
-rw-r--r-- | src/options/view.rs | 84 | ||||
-rw-r--r-- | src/output/cell.rs | 32 | ||||
-rw-r--r-- | src/output/file_name.rs | 4 | ||||
-rw-r--r-- | src/output/icons.rs | 6 | ||||
-rw-r--r-- | src/output/render/blocks.rs | 4 | ||||
-rw-r--r-- | src/output/render/filetype.rs | 16 | ||||
-rw-r--r-- | src/output/render/git.rs | 16 | ||||
-rw-r--r-- | src/output/render/size.rs | 6 | ||||
-rw-r--r-- | src/output/table.rs | 54 | ||||
-rw-r--r-- | src/output/time.rs | 28 | ||||
-rw-r--r-- | src/output/tree.rs | 20 | ||||
-rw-r--r-- | src/style/colours.rs | 8 |
26 files changed, 251 insertions, 251 deletions
diff --git a/src/fs/dir.rs b/src/fs/dir.rs index 9b87ff5..a02c3e2 100644 --- a/src/fs/dir.rs +++ b/src/fs/dir.rs @@ -35,14 +35,14 @@ impl Dir { /// The `read_dir` iterator doesn’t actually yield the `.` and `..` /// entries, so if the user wants to see them, we’ll have to add them /// ourselves after the files have been read. - pub fn read_dir(path: PathBuf) -> IOResult<Dir> { + pub fn read_dir(path: PathBuf) -> IOResult<Self> { info!("Reading directory {:?}", &path); let contents = fs::read_dir(&path)? .map(|result| result.map(|entry| entry.path())) .collect::<Result<_,_>>()?; - Ok(Dir { contents, path }) + Ok(Self { contents, path }) } /// Produce an iterator of IO results of trying to read all the files in @@ -180,8 +180,8 @@ pub enum DotFilter { } impl Default for DotFilter { - fn default() -> DotFilter { - DotFilter::JustFiles + fn default() -> Self { + Self::JustFiles } } @@ -190,18 +190,18 @@ impl DotFilter { /// Whether this filter should show dotfiles in a listing. fn shows_dotfiles(self) -> bool { match self { - DotFilter::JustFiles => false, - DotFilter::Dotfiles => true, - DotFilter::DotfilesAndDots => true, + Self::JustFiles => false, + Self::Dotfiles => true, + Self::DotfilesAndDots => true, } } /// Whether this filter should add dot directories to a listing. fn dots(self) -> DotsNext { match self { - DotFilter::JustFiles => DotsNext::Files, - DotFilter::Dotfiles => DotsNext::Files, - DotFilter::DotfilesAndDots => DotsNext::Dot, + Self::JustFiles => DotsNext::Files, + Self::Dotfiles => DotsNext::Files, + Self::DotfilesAndDots => DotsNext::Dot, } } } diff --git a/src/fs/dir_action.rs b/src/fs/dir_action.rs index ce382ac..d72db88 100644 --- a/src/fs/dir_action.rs +++ b/src/fs/dir_action.rs @@ -41,7 +41,7 @@ impl DirAction { /// Gets the recurse options, if this dir action has any. pub fn recurse_options(&self) -> Option<RecurseOptions> { match *self { - DirAction::Recurse(o) => Some(o), + Self::Recurse(o) => Some(o), _ => None, } } @@ -49,8 +49,8 @@ impl DirAction { /// Whether to treat directories as regular files or not. pub fn treat_dirs_as_files(&self) -> bool { match *self { - DirAction::AsFile => true, - DirAction::Recurse(o) => o.tree, + Self::AsFile => true, + Self::Recurse(o) => o.tree, _ => false, } } diff --git a/src/fs/feature/git.rs b/src/fs/feature/git.rs index 7cf68a8..05b15ef 100644 --- a/src/fs/feature/git.rs +++ b/src/fs/feature/git.rs @@ -38,7 +38,7 @@ use std::iter::FromIterator; impl FromIterator<PathBuf> for GitCache { fn from_iter<I: IntoIterator<Item=PathBuf>>(iter: I) -> Self { let iter = iter.into_iter(); - let mut git = GitCache { + let mut git = Self { repos: Vec::with_capacity(iter.size_hint().0), misses: Vec::new(), }; @@ -152,7 +152,7 @@ impl GitRepo { /// Searches for a Git repository at any point above the given path. /// Returns the original buffer if none is found. - fn discover(path: PathBuf) -> Result<GitRepo, PathBuf> { + fn discover(path: PathBuf) -> Result<Self, PathBuf> { info!("Searching for Git repository above {:?}", path); let repo = match git2::Repository::discover(&path) { Ok(r) => r, @@ -165,7 +165,7 @@ impl GitRepo { match repo.workdir().map(|wd| wd.to_path_buf()) { Some(workdir) => { let contents = Mutex::new(GitContents::Before { repo }); - Ok(GitRepo { contents, workdir, original_path: path, extra_paths: Vec::new() }) + Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() }) }, None => { warn!("Repository has no workdir?"); @@ -181,7 +181,7 @@ impl GitContents { /// (consuming the value) if it has. This is needed because the entire /// enum variant gets replaced when a repo is queried (see above). fn inner_repo(self) -> git2::Repository { - if let GitContents::Before { repo } = self { + if let Self::Before { repo } = self { repo } else { diff --git a/src/fs/feature/xattr.rs b/src/fs/feature/xattr.rs index f39e3c8..d028e17 100644 --- a/src/fs/feature/xattr.rs +++ b/src/fs/feature/xattr.rs @@ -126,13 +126,13 @@ mod lister { } impl Lister { - pub fn new(do_follow: FollowSymlinks) -> Lister { + pub fn new(do_follow: FollowSymlinks) -> Self { let c_flags: c_int = match do_follow { FollowSymlinks::Yes => 0x0001, FollowSymlinks::No => 0x0000, }; - Lister { c_flags } + Self { c_flags } } pub fn translate_attribute_name(&self, input: &[u8]) -> String { diff --git a/src/fs/fields.rs b/src/fs/fields.rs index f3d6735..28c022d 100644 --- a/src/fs/fields.rs +++ b/src/fs/fields.rs @@ -50,7 +50,7 @@ pub enum Type { impl Type { pub fn is_regular_file(&self) -> bool { - matches!(*self, Type::File) + matches!(*self, Self::File) } } @@ -220,7 +220,7 @@ use std::default::Default; impl Default for Git { /// Create a Git status for a file with nothing done to it. - fn default() -> Git { - Git { staged: GitStatus::NotModified, unstaged: GitStatus::NotModified } + fn default() -> Self { + Self { staged: GitStatus::NotModified, unstaged: GitStatus::NotModified } } } diff --git a/src/fs/filter.rs b/src/fs/filter.rs index c7e2169..937caff 100644 --- a/src/fs/filter.rs +++ b/src/fs/filter.rs @@ -240,41 +240,41 @@ impl SortField { use self::SortCase::{ABCabc, AaBbCc}; match self { - SortField::Unsorted => Ordering::Equal, + Self::Unsorted => Ordering::Equal, - SortField::Name(ABCabc) => natord::compare(&a.name, &b.name), - SortField::Name(AaBbCc) => natord::compare_ignore_case(&a.name, &b.name), + Self::Name(ABCabc) => natord::compare(&a.name, &b.name), + Self::Name(AaBbCc) => natord::compare_ignore_case(&a.name, &b.name), - SortField::Size => a.metadata.len().cmp(&b.metadata.len()), - SortField::FileInode => a.metadata.ino().cmp(&b.metadata.ino()), - SortField::ModifiedDate => a.modified_time().cmp(&b.modified_time()), - SortField::AccessedDate => a.accessed_time().cmp(&b.accessed_time()), - SortField::ChangedDate => a.changed_time().cmp(&b.changed_time()), - SortField::CreatedDate => a.created_time().cmp(&b.created_time()), - SortField::ModifiedAge => b.modified_time().cmp(&a.modified_time()), // flip b and a + Self::Size => a.metadata.len().cmp(&b.metadata.len()), + Self::FileInode => a.metadata.ino().cmp(&b.metadata.ino()), + Self::ModifiedDate => a.modified_time().cmp(&b.modified_time()), + Self::AccessedDate => a.accessed_time().cmp(&b.accessed_time()), + Self::ChangedDate => a.changed_time().cmp(&b.changed_time()), + Self::CreatedDate => a.created_time().cmp(&b.created_time()), + Self::ModifiedAge => b.modified_time().cmp(&a.modified_time()), // flip b and a - SortField::FileType => match a.type_char().cmp(&b.type_char()) { // todo: this recomputes + Self::FileType => match a.type_char().cmp(&b.type_char()) { // todo: this recomputes Ordering::Equal => natord::compare(&*a.name, &*b.name), order => order, }, - SortField::Extension(ABCabc) => match a.ext.cmp(&b.ext) { + Self::Extension(ABCabc) => match a.ext.cmp(&b.ext) { Ordering::Equal => natord::compare(&*a.name, &*b.name), order => order, }, - SortField::Extension(AaBbCc) => match a.ext.cmp(&b.ext) { + Self::Extension(AaBbCc) => match a.ext.cmp(&b.ext) { Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name), order => order, }, - SortField::NameMixHidden(ABCabc) => natord::compare( - SortField::strip_dot(&a.name), - SortField::strip_dot(&b.name) + Self::NameMixHidden(ABCabc) => natord::compare( + Self::strip_dot(&a.name), + Self::strip_dot(&b.name) ), - SortField::NameMixHidden(AaBbCc) => natord::compare_ignore_case( - SortField::strip_dot(&a.name), - SortField::strip_dot(&b.name) + Self::NameMixHidden(AaBbCc) => natord::compare_ignore_case( + Self::strip_dot(&a.name), + Self::strip_dot(&b.name) ) } } @@ -299,7 +299,7 @@ pub struct IgnorePatterns { impl FromIterator<glob::Pattern> for IgnorePatterns { fn from_iter<I: IntoIterator<Item = glob::Pattern>>(iter: I) -> Self { - IgnorePatterns { patterns: iter.into_iter().collect() } + Self { patterns: iter.into_iter().collect() } } } @@ -328,12 +328,12 @@ impl IgnorePatterns { } } - (IgnorePatterns { patterns }, errors) + (Self { patterns }, errors) } /// Create a new empty set of patterns that matches nothing. - pub fn empty() -> IgnorePatterns { - IgnorePatterns { patterns: Vec::new() } + pub fn empty() -> Self { + Self { patterns: Vec::new() } } /// Test whether the given file should be hidden from the results. diff --git a/src/options/dir_action.rs b/src/options/dir_action.rs index 119fc95..7316ddf 100644 --- a/src/options/dir_action.rs +++ b/src/options/dir_action.rs @@ -12,7 +12,7 @@ impl DirAction { /// There are three possible actions, and they overlap somewhat: the /// `--tree` flag is another form of recursion, so those two are allowed /// to both be present, but the `--list-dirs` flag is used separately. - pub fn deduce(matches: &MatchedFlags) -> Result<DirAction, Misfire> { + pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { let recurse = matches.has(&flags::RECURSE)?; let as_file = matches.has(&flags::LIST_DIRS)?; let tree = matches.has(&flags::TREE)?; @@ -31,16 +31,16 @@ impl DirAction { } if tree { - Ok(DirAction::Recurse(RecurseOptions::deduce(matches, true)?)) + Ok(Self::Recurse(RecurseOptions::deduce(matches, true)?)) } else if recurse { - Ok(DirAction::Recurse(RecurseOptions::deduce(matches, false)?)) + Ok(Self::Recurse(RecurseOptions::deduce(matches, false)?)) } else if as_file { - Ok(DirAction::AsFile) + Ok(Self::AsFile) } else { - Ok(DirAction::List) + Ok(Self::List) } } } @@ -52,7 +52,7 @@ impl RecurseOptions { /// flag’s value, and whether the `--tree` flag was passed, which was /// determined earlier. The maximum level should be a number, and this /// will fail with an `Err` if it isn’t. - pub fn deduce(matches: &MatchedFlags, tree: bool) -> Result<RecurseOptions, Misfire> { + pub fn deduce(matches: &MatchedFlags, tree: bool) -> Result<Self, Misfire> { let max_depth = if let Some(level) = matches.get(&flags::LEVEL)? { match level.to_string_lossy().parse() { Ok(l) => Some(l), @@ -63,7 +63,7 @@ impl RecurseOptions { None }; - Ok(RecurseOptions { tree, max_depth }) + Ok(Self { tree, max_depth }) } } diff --git a/src/options/filter.rs b/src/options/filter.rs index 48607fe..9005b66 100644 --- a/src/options/filter.rs +++ b/src/options/filter.rs @@ -10,8 +10,8 @@ use crate::options::parser::MatchedFlags; impl FileFilter { /// Determines which of all the file filter options to use. - pub fn deduce(matches: &MatchedFlags) -> Result<FileFilter, Misfire> { - Ok(FileFilter { + pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { + Ok(Self { list_dirs_first: matches.has(&flags::DIRS_FIRST)?, reverse: matches.has(&flags::REVERSE)?, only_dirs: matches.has(&flags::ONLY_DIRS)?, @@ -29,10 +29,10 @@ impl SortField { /// This argument’s value can be one of several flags, listed above. /// Returns the default sort field if none is given, or `Err` if the /// value doesn’t correspond to a sort field we know about. - fn deduce(matches: &MatchedFlags) -> Result<SortField, Misfire> { + fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { let word = match matches.get(&flags::SORT)? { Some(w) => w, - None => return Ok(SortField::default()), + None => return Ok(Self::default()), }; // Get String because we can’t match an OsStr @@ -42,28 +42,28 @@ impl SortField { }; let field = match word { - "name" | "filename" => SortField::Name(SortCase::AaBbCc), - "Name" | "Filename" => SortField::Name(SortCase::ABCabc), - ".name" | ".filename" => SortField::NameMixHidden(SortCase::AaBbCc), - ".Name" | ".Filename" => SortField::NameMixHidden(SortCase::ABCabc), - "size" | "filesize" => SortField::Size, - "ext" | "extension" => SortField::Extension(SortCase::AaBbCc), - "Ext" | "Extension" => SortField::Extension(SortCase::ABCabc), + "name" | "filename" => Self::Name(SortCase::AaBbCc), + "Name" | "Filename" => Self::Name(SortCase::ABCabc), + ".name" | ".filename" => Self::NameMixHidden(SortCase::AaBbCc), + ".Name" | ".Filename" => Self::NameMixHidden(SortCase::ABCabc), + "size" | "filesize" => Self::Size, + "ext" | "extension" => Self::Extension(SortCase::AaBbCc), + "Ext" | "Extension" => Self::Extension(SortCase::ABCabc), // “new” sorts oldest at the top and newest at the bottom; “old” // sorts newest at the top and oldest at the bottom. I think this // is the right way round to do this: “size” puts the smallest at // the top and the largest at the bottom, doesn’t it? - "date" | "time" | "mod" | "modified" | "new" | "newest" => SortField::ModifiedDate, + "date" | "time" | "mod" | "modified" | "new" | "newest" => Self::ModifiedDate, // Similarly, “age” means that files with the least age (the // newest files) get sorted at the top, and files with the most // age (the oldest) at the bottom. - "age" | "old" | "oldest" => SortField::ModifiedAge, - "ch" | "changed" => SortField::ChangedDate, - "acc" | "accessed" => SortField::AccessedDate, - "cr" | "created" => SortField::CreatedDate, - "inode" => SortField::FileInode, - "type" => SortField::FileType, - "none" => SortField::Unsorted, + "age" | "old" | "oldest" => Self::ModifiedAge, + "ch" | "changed" => Self::ChangedDate, + "acc" | "accessed" => Self::AccessedDate, + "cr" | "created" => Self::CreatedDate, + "inode" => Self::FileInode, + "type" => Self::FileType, + "none" => Self::Unsorted, _ => return Err(Misfire::BadArgument(&flags::SORT, word.into())) }; @@ -105,8 +105,8 @@ impl SortField { // You can get the old behaviour back by sorting with `--sort=Name`. impl Default for SortField { - fn default() -> SortField { - SortField::Name(SortCase::AaBbCc) + fn default() -> Self { + Self::Name(SortCase::AaBbCc) } } @@ -119,14 +119,14 @@ impl DotFilter { /// It also checks for the `--tree` option in strict mode, because of a /// special case where `--tree --all --all` won’t work: listing the /// parent directory in tree mode would loop onto itself! - pub fn deduce(matches: &MatchedFlags) -> Result<DotFilter, Misfire> { + pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { let count = matches.count(&flags::ALL); if count == 0 { - Ok(DotFilter::JustFiles) + Ok(Self::JustFiles) } else if count == 1 { - Ok(DotFilter::Dotfiles) + Ok(Self::Dotfiles) } else if matches.count(&flags::TREE) > 0 { Err(Misfire::TreeAllAll) @@ -135,7 +135,7 @@ impl DotFilter { Err(Misfire::Conflict(&flags::ALL, &flags::ALL)) } else { - Ok(DotFilter::DotfilesAndDots) + Ok(Self::DotfilesAndDots) } } } @@ -146,18 +146,18 @@ impl IgnorePatterns { /// Determines the set of glob patterns to use based on the /// `--ignore-glob` argument’s value. This is a list of strings /// separated by pipe (`|`) characters, given in any order. - pub fn deduce(matches: &MatchedFlags) -> Result<IgnorePatterns, Misfire> { + pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { // If there are no inputs, we return a set of patterns that doesn’t // match anything, rather than, say, `None`. let inputs = match matches.get(&flags::IGNORE_GLOB)? { - None => return Ok(IgnorePatterns::empty()), + None => return Ok(Self::empty()), Some(is) => is, }; // Awkwardly, though, a glob pattern can be invalid, and we need to // deal with invalid patterns somehow. - let (patterns, mut errors) = IgnorePatterns::parse_from_iter(inputs.to_string_lossy().split('|')); + let (patterns, mut errors) = Self::parse_from_iter(inputs.to_string_lossy().split('|')); // It can actually return more than one glob error, // but we only use one. (TODO) @@ -171,8 +171,8 @@ impl IgnorePatterns { impl GitIgnore { pub fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { - Ok(if matches.has(&flags::GIT_IGNORE)? { GitIgnore::CheckAndIgnore } - else { GitIgnore::Off }) + Ok(if matches.has(&flags::GIT_IGNORE)? { Self::CheckAndIgnore } + else { Self::Off }) } } diff --git a/src/options/help.rs b/src/options/help.rs index c934fea..d4d6bc5 100644 --- a/src/options/help.rs +++ b/src/options/help.rs @@ -86,12 +86,12 @@ impl HelpString { /// We don’t do any strict-mode error checking here: it’s OK to give /// the --help or --long flags more than once. Actually checking for /// errors when the user wants help is kind of petty! - pub fn deduce(matches: &MatchedFlags) -> Result<(), HelpString> { + pub fn deduce(matches: &MatchedFlags) -> Result<(), Self> { if matches.count(&flags::HELP) > 0 { let only_long = matches.count(&flags::LONG) > 0; let git = cfg!(feature="git"); let xattrs = xattr::ENABLED; - Err(HelpString { only_long, git, xattrs }) + Err(Self { only_long, git, xattrs }) } else { Ok(()) // no help needs to be shown diff --git a/src/options/misfire.rs b/src/options/misfire.rs index f0bf9f4..0f86a54 100644 --- a/src/options/misfire.rs +++ b/src/options/misfire.rs @@ -56,16 +56,16 @@ impl Misfire { /// The OS return code this misfire should signify. pub fn is_error(&self) -> bool { match *self { - Misfire::Help(_) => false, - Misfire::Version(_) => false, + Self::Help(_) => false, + Self::Version(_) => false, _ => true, } } } impl From<glob::PatternError> for Misfire { - fn from(error: glob::PatternError) -> Misfire { - Misfire::FailedGlobPattern(error.to_string()) + fn from(error: glob::PatternError) -> Self { + Self::FailedGlobPattern(error.to_string()) } } @@ -120,9 +120,9 @@ impl Misfire { pub fn suggestion(&self) -> Option<&'static str> { // ‘ls -lt’ and ‘ls -ltr’ are common combinations match *self { - Misfire::BadArgument(ref time, ref r) if *time == &flags::TIME && r == "r" => + Self::BadArgument(ref time, ref r) if *time == &flags::TIME && r == "r" => Some("To sort oldest files last, try \"--sort oldest\", or just \"-sold\""), - Misfire::InvalidOptions(ParseError::NeedsValue { ref flag, .. }) if *flag == Flag::Short(b't') => + Self::InvalidOptions(ParseError::NeedsValue { ref flag, .. }) if *flag == Flag::Short(b't') => Some("To sort newest files last, try \"--sort newest\", or just \"-snew\""), _ => None } diff --git a/src/options/mod.rs b/src/options/mod.rs index 620a5a9..dd9896c 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -119,7 +119,7 @@ impl Options { /// struct and a list of free filenames, using the environment variables /// for extra options. #[allow(unused_results)] - pub fn parse<'args, I, V>(args: I, vars: &V) -> Result<(Options, Vec<&'args OsStr>), Misfire> + pub fn parse<'args, I, V>(args: I, vars: &V) -> Result<(Self, Vec<&'args OsStr>), Misfire> where I: IntoIterator<Item=&'args OsString>, V: Vars { use crate::options::parser::{Matches, Strictness}; @@ -138,7 +138,7 @@ impl Options { HelpString::deduce(&flags).map_err(Misfire::Help)?; VersionString::deduce(&flags).map_err(Misfire::Version)?; - let options = Options::deduce(&flags, vars)?; + let options = Self::deduce(&flags, vars)?; Ok((options, frees)) } @@ -159,12 +159,12 @@ impl Options { /// Determines the complete set of options based on the given command-line /// arguments, after they’ve been parsed. - fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Options, Misfire> { + fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> { let dir_action = DirAction::deduce(matches)?; let filter = FileFilter::deduce(matches)?; let view = View::deduce(matches, vars)?; - Ok(Options { dir_action, view, filter }) + Ok(Self { dir_action, view, filter }) } } diff --git a/src/options/parser.rs b/src/options/parser.rs index 909538c..ef4072b 100644 --- a/src/options/parser.rs +++ b/src/options/parser.rs @@ -61,8 +61,8 @@ pub enum Flag { impl Flag { pub fn matches(&self, arg: &Arg) -> bool { match *self { - Flag::Short(short) => arg.short == Some(short), - Flag::Long(long) => arg.long == long, + Self::Short(short) => arg.short == Some(short), + Self::Long(long) => arg.long == long, } } } @@ -70,8 +70,8 @@ impl Flag { impl fmt::Display for Flag { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match *self { - Flag::Short(short) => write!(f, "-{}", short as char), - Flag::Long(long) => write!(f, "--{}", long), + Self::Short(short) => write!(f, "-{}", short as char), + Self::Long(long) => write!(f, "--{}", long), } } } diff --git a/src/options/style.rs b/src/options/style.rs index 133e0df..3f5b3fe 100644 --- a/src/options/style.rs +++ b/src/options/style.rs @@ -28,8 +28,8 @@ enum TerminalColours { } impl Default for TerminalColours { - fn default() -> TerminalColours { - TerminalColours::Automatic + fn default() -> Self { + Self::Automatic } } @@ -37,21 +37,21 @@ impl Default for TerminalColours { impl TerminalColours { /// Determine which terminal colour conditions to use. - fn deduce(matches: &MatchedFlags) -> Result<TerminalColours, Misfire> { + fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { let word = match matches.get_where(|f| f.matches(&flags::COLOR) || f.matches(&flags::COLOUR))? { Some(w) => w, - None => return Ok(TerminalColours::default()), + None => return Ok(Self::default()), }; if word == "always" { - Ok(TerminalColours::Always) + Ok(Self::Always) } else if word == "auto" || word == "automatic" { - Ok(TerminalColours::Automatic) + Ok(Self::Automatic) } else if word == "never" { - Ok(TerminalColours::Never) + Ok(Self::Never) } else { Err(Misfire::BadArgument(&flags::COLOR, word.into())) @@ -90,7 +90,7 @@ impl Styles { // custom colours at all let tc = TerminalColours::deduce(matches)?; if tc == Never || (tc == Automatic && widther().is_none()) { - return Ok(Styles { + return Ok(Self { colours: Colours::plain(), style: FileStyle { classify, exts: Box::new(NoFileColours) }, }); @@ -111,7 +111,7 @@ impl Styles { }; let style = FileStyle { classify, exts }; - Ok(Styles { colours, style }) + Ok(Self { colours, style }) } } @@ -197,11 +197,11 @@ impl ExtensionMappings { impl Classify { - fn deduce(matches: &MatchedFlags) -> Result<Classify, Misfire> { + fn deduce(matches: &MatchedFlags) -> Result<Self, Misfire> { let flagged = matches.has(&flags::CLASSIFY)?; - Ok(if flagged { Classify::AddFileIndicators } - else { Classify::JustFilenames }) + Ok(if flagged { Self::AddFileIndicators } + else { Self::JustFilenames }) } } diff --git a/src/options/version.rs b/src/options/version.rs index 0b26c07..ae151b4 100644 --- a/src/options/version.rs +++ b/src/options/version.rs @@ -19,9 +19,9 @@ impl VersionString { /// ‘deduce’ functions, returning Err if help needs to be shown. /// /// Like --help, this doesn’t bother checking for errors. - pub fn deduce(matches: &MatchedFlags) -> Result<(), VersionString> { + pub fn deduce(matches: &MatchedFlags) -> Result<(), Self> { if matches.count(&flags::VERSION) > 0 { - Err(VersionString) + Err(Self) } else { Ok(()) // no version needs to be shown diff --git a/src/options/view.rs b/src/options/view.rs index cb17cde..72a2e55 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -13,12 +13,12 @@ use crate::fs::feature::xattr; impl View { /// Determine which view to use and all of that view’s arguments. - pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<View, Misfire> { + pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> { use crate::options::style::Styles; let mode = Mode::deduce(matches, vars)?; let Styles { colours, style } = Styles::deduce(matches, vars, || *TERM_WIDTH)?; - Ok(View { mode, colours, style }) + Ok(Self { mode, colours, style }) } } @@ -26,7 +26,7 @@ impl View { impl Mode { /// Determine the mode from the command-line arguments. - pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Mode, Misfire> { + pub fn deduce<V: Vars>(matches: &MatchedFlags, vars: &V) -> Result<Self, Misfire> { use crate::options::misfire::Misfire::*; let long = || { @@ -54,7 +54,7 @@ impl Mode { } else { let lines = lines::Options { icons: matches.has(&flags::ICONS)? }; - Ok(Mode::Lines(lines)) + Ok(Self::Lines(lines)) } } else if matches.has(&flags::TREE)? { @@ -65,7 +65,7 @@ impl Mode { icons: matches.has(&flags::ICONS)?, }; - Ok(Mode::Details(details)) + Ok(Self::Details(details)) } else { let grid = grid::Options { @@ -74,7 +74,7 @@ impl Mode { icons: matches.has(&flags::ICONS)?, }; - Ok(Mode::Grid(grid)) + Ok(Self::Grid(grid)) } } @@ -89,14 +89,14 @@ impl Mode { icons: matches.has(&flags::ICONS)?, }; - Ok(Mode::Details(details)) + Ok(Self::Details(details)) } else if matches.has(&flags::LONG)? { let details = long()?; - Ok(Mode::Details(details)) + Ok(Self::Details(details)) } else { let li |