Merge pull request #1125 from Tyrubias/upgrade-and-cleanup

Upgrade both Rust version and edition (and fix some lints)
This commit is contained in:
Mélanie Chauvel 2023-03-01 15:17:36 +01:00 committed by GitHub
commit c697d06670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 115 additions and 118 deletions

View File

@ -28,7 +28,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest]
rust: [1.56.1, stable, beta, nightly] rust: [1.63.0, stable, beta, nightly]
steps: steps:
- name: Checkout repository - name: Checkout repository

View File

@ -3,8 +3,8 @@ name = "exa"
description = "A modern replacement for ls" description = "A modern replacement for ls"
authors = ["Benjamin Sago <ogham@bsago.me>"] authors = ["Benjamin Sago <ogham@bsago.me>"]
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
edition = "2018" edition = "2021"
rust-version = "1.56.1" rust-version = "1.63.0"
exclude = ["/devtools/*", "/Justfile", "/Vagrantfile", "/screenshots.png"] exclude = ["/devtools/*", "/Justfile", "/Vagrantfile", "/screenshots.png"]
readme = "README.md" readme = "README.md"
homepage = "https://the.exa.website/" homepage = "https://the.exa.website/"

View File

@ -196,8 +196,8 @@ To build without Git support, run `cargo install --no-default-features exa` is a
<a id="development"> <a id="development">
<h1>Development <h1>Development
<a href="https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html"> <a href="https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html">
<img src="https://img.shields.io/badge/rustc-1.56.1+-lightgray.svg" alt="Rust 1.56.1+" /> <img src="https://img.shields.io/badge/rustc-1.63.0+-lightgray.svg" alt="Rust 1.63.0+" />
</a> </a>
<a href="https://github.com/ogham/exa/blob/master/LICENCE"> <a href="https://github.com/ogham/exa/blob/master/LICENCE">

View File

@ -41,7 +41,7 @@ fn main() -> io::Result<()> {
let path = &out.join("version_string.txt"); let path = &out.join("version_string.txt");
// Bland version text // Bland version text
let mut f = File::create(path).expect(&path.to_string_lossy()); let mut f = File::create(path).unwrap_or_else(|_| { panic!("{}", path.to_string_lossy().to_string()) });
writeln!(f, "{}", strip_codes(&ver))?; writeln!(f, "{}", strip_codes(&ver))?;
Ok(()) Ok(())

View File

@ -1,2 +1,2 @@
[toolchain] [toolchain]
channel = "1.56.1" channel = "1.63.0"

View File

@ -176,7 +176,7 @@ impl<'dir, 'ig> Iterator for Files<'dir, 'ig> {
/// Usually files in Unix use a leading dot to be hidden or visible, but two /// Usually files in Unix use a leading dot to be hidden or visible, but two
/// entries in particular are “extra-hidden”: `.` and `..`, which only become /// entries in particular are “extra-hidden”: `.` and `..`, which only become
/// visible after an extra `-a` option. /// visible after an extra `-a` option.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum DotFilter { pub enum DotFilter {
/// Shows files, dotfiles, and `.` and `..`. /// Shows files, dotfiles, and `.` and `..`.

View File

@ -19,7 +19,7 @@
/// into them and print out their contents. The recurse mode does this by /// into them and print out their contents. The recurse mode does this by
/// having extra output blocks at the end, while the tree mode will show /// having extra output blocks at the end, while the tree mode will show
/// directories inline, with their contents immediately underneath. /// directories inline, with their contents immediately underneath.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum DirAction { pub enum DirAction {
/// This directory should be listed along with the regular files, instead /// This directory should be listed along with the regular files, instead
@ -58,7 +58,7 @@ impl DirAction {
/// The options that determine how to recurse into a directory. /// The options that determine how to recurse into a directory.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct RecurseOptions { pub struct RecurseOptions {
/// Whether recursion should be done as a tree or as multiple individual /// Whether recursion should be done as a tree or as multiple individual

View File

@ -167,7 +167,7 @@ mod lister {
unsafe { unsafe {
listxattr( listxattr(
c_path.as_ptr(), c_path.as_ptr(),
buf.as_mut_ptr() as *mut c_char, buf.as_mut_ptr().cast::<c_char>(),
bufsize as size_t, bufsize as size_t,
self.c_flags, self.c_flags,
) )
@ -178,7 +178,7 @@ mod lister {
unsafe { unsafe {
getxattr( getxattr(
c_path.as_ptr(), c_path.as_ptr(),
buf.as_ptr() as *const c_char, buf.as_ptr().cast::<c_char>(),
ptr::null_mut(), ptr::null_mut(),
0, 0,
0, 0,

View File

@ -210,7 +210,7 @@ pub struct Time {
/// A files status in a Git repository. Whether a file is in a repository or /// A files status in a Git repository. Whether a file is in a repository or
/// not is handled by the Git module, rather than having a “null” variant in /// not is handled by the Git module, rather than having a “null” variant in
/// this enum. /// this enum.
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Eq, Copy, Clone)]
pub enum GitStatus { pub enum GitStatus {
/// This file hasnt changed since the last commit. /// This file hasnt changed since the last commit.

View File

@ -221,13 +221,13 @@ impl<'dir> File<'dir> {
path.to_path_buf() path.to_path_buf()
} }
else if let Some(dir) = self.parent_dir { else if let Some(dir) = self.parent_dir {
dir.join(&*path) dir.join(path)
} }
else if let Some(parent) = self.path.parent() { else if let Some(parent) = self.path.parent() {
parent.join(&*path) parent.join(path)
} }
else { else {
self.path.join(&*path) self.path.join(path)
} }
} }
@ -375,7 +375,7 @@ impl<'dir> File<'dir> {
nanosec -= 1_000_000_000; nanosec -= 1_000_000_000;
} }
let duration = Duration::new(sec.abs() as u64, nanosec.abs() as u32); let duration = Duration::new(sec.unsigned_abs(), nanosec.unsigned_abs() as u32);
Some(UNIX_EPOCH - duration) Some(UNIX_EPOCH - duration)
} }
else { else {

View File

@ -23,7 +23,7 @@ use crate::fs::File;
/// The filter also governs sorting the list. After being filtered, pairs of /// The filter also governs sorting the list. After being filtered, pairs of
/// files are compared and sorted based on the result, with the sort field /// files are compared and sorted based on the result, with the sort field
/// performing the comparison. /// performing the comparison.
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub struct FileFilter { pub struct FileFilter {
/// Whether directories should be listed first, and other types of file /// Whether directories should be listed first, and other types of file
@ -89,7 +89,7 @@ impl FileFilter {
} }
/// Sort the files in the given vector based on the sort field option. /// Sort the files in the given vector based on the sort field option.
pub fn sort_files<'a, F>(&self, files: &mut Vec<F>) pub fn sort_files<'a, F>(&self, files: &mut [F])
where F: AsRef<File<'a>> where F: AsRef<File<'a>>
{ {
files.sort_by(|a, b| { files.sort_by(|a, b| {
@ -113,7 +113,7 @@ impl FileFilter {
/// User-supplied field to sort by. /// User-supplied field to sort by.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SortField { pub enum SortField {
/// Dont apply any sorting. This is usually used as an optimisation in /// Dont apply any sorting. This is usually used as an optimisation in
@ -194,7 +194,7 @@ pub enum SortField {
/// lowercase letters because it takes the difference between the two cases /// lowercase letters because it takes the difference between the two cases
/// into account? I gave up and just named these two variants after the /// into account? I gave up and just named these two variants after the
/// effects they have. /// effects they have.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SortCase { pub enum SortCase {
/// Sort files case-sensitively with uppercase first, with A coming /// Sort files case-sensitively with uppercase first, with A coming
@ -271,7 +271,7 @@ impl SortField {
/// The **ignore patterns** are a list of globs that are tested against /// The **ignore patterns** are a list of globs that are tested against
/// each filename, and if any of them match, that file isnt displayed. /// each filename, and if any of them match, that file isnt displayed.
/// This lets a user hide, say, text files by ignoring `*.txt`. /// This lets a user hide, say, text files by ignoring `*.txt`.
#[derive(PartialEq, Default, Debug, Clone)] #[derive(PartialEq, Eq, Default, Debug, Clone)]
pub struct IgnorePatterns { pub struct IgnorePatterns {
patterns: Vec<glob::Pattern>, patterns: Vec<glob::Pattern>,
} }
@ -327,7 +327,7 @@ impl IgnorePatterns {
/// Whether to ignore or display files that Git would ignore. /// Whether to ignore or display files that Git would ignore.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum GitIgnore { pub enum GitIgnore {
/// Ignore files that Git would ignore. /// Ignore files that Git would ignore.
@ -346,31 +346,31 @@ mod test_ignores {
#[test] #[test]
fn empty_matches_nothing() { fn empty_matches_nothing() {
let pats = IgnorePatterns::empty(); let pats = IgnorePatterns::empty();
assert_eq!(false, pats.is_ignored("nothing")); assert!(!pats.is_ignored("nothing"));
assert_eq!(false, pats.is_ignored("test.mp3")); assert!(!pats.is_ignored("test.mp3"));
} }
#[test] #[test]
fn ignores_a_glob() { fn ignores_a_glob() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "*.mp3" ]); let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "*.mp3" ]);
assert!(fails.is_empty()); assert!(fails.is_empty());
assert_eq!(false, pats.is_ignored("nothing")); assert!(!pats.is_ignored("nothing"));
assert_eq!(true, pats.is_ignored("test.mp3")); assert!(pats.is_ignored("test.mp3"));
} }
#[test] #[test]
fn ignores_an_exact_filename() { fn ignores_an_exact_filename() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing" ]); let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing" ]);
assert!(fails.is_empty()); assert!(fails.is_empty());
assert_eq!(true, pats.is_ignored("nothing")); assert!(pats.is_ignored("nothing"));
assert_eq!(false, pats.is_ignored("test.mp3")); assert!(!pats.is_ignored("test.mp3"));
} }
#[test] #[test]
fn ignores_both() { fn ignores_both() {
let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing", "*.mp3" ]); let (pats, fails) = IgnorePatterns::parse_from_iter(vec![ "nothing", "*.mp3" ]);
assert!(fails.is_empty()); assert!(fails.is_empty());
assert_eq!(true, pats.is_ignored("nothing")); assert!(pats.is_ignored("nothing"));
assert_eq!(true, pats.is_ignored("test.mp3")); assert!(pats.is_ignored("test.mp3"));
} }
} }

View File

@ -11,7 +11,7 @@ use crate::output::icons::FileIcon;
use crate::theme::FileColours; use crate::theme::FileColours;
#[derive(Debug, Default, PartialEq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct FileExtensions; pub struct FileExtensions;
impl FileExtensions { impl FileExtensions {

View File

@ -62,7 +62,7 @@ fn main() {
} }
let args: Vec<_> = env::args_os().skip(1).collect(); let args: Vec<_> = env::args_os().skip(1).collect();
match Options::parse(args.iter().map(|e| e.as_ref()), &LiveVars) { match Options::parse(args.iter().map(std::convert::AsRef::as_ref), &LiveVars) {
OptionsResult::Ok(options, mut input_paths) => { OptionsResult::Ok(options, mut input_paths) => {
// List the current directory by default. // List the current directory by default.

View File

@ -7,7 +7,7 @@ use crate::options::parser::{Arg, Flag, ParseError};
/// Something wrong with the combination of options the user has picked. /// Something wrong with the combination of options the user has picked.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum OptionsError { pub enum OptionsError {
/// There was an error (from `getopts`) parsing the arguments. /// There was an error (from `getopts`) parsing the arguments.
@ -44,7 +44,7 @@ pub enum OptionsError {
} }
/// The source of a string that failed to be parsed as a number. /// The source of a string that failed to be parsed as a number.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum NumberSource { pub enum NumberSource {
/// It came... from a command-line argument! /// It came... from a command-line argument!
@ -119,7 +119,7 @@ impl OptionsError {
/// A list of legal choices for an argument-taking option. /// A list of legal choices for an argument-taking option.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Choices(pub &'static [&'static str]); pub struct Choices(pub &'static [&'static str]);
impl fmt::Display for Choices { impl fmt::Display for Choices {

View File

@ -295,7 +295,6 @@ mod test {
mod ignore_patterns { mod ignore_patterns {
use super::*; use super::*;
use std::iter::FromIterator; use std::iter::FromIterator;
use glob;
fn pat(string: &'static str) -> glob::Pattern { fn pat(string: &'static str) -> glob::Pattern {
glob::Pattern::new(string).unwrap() glob::Pattern::new(string).unwrap()

View File

@ -69,7 +69,7 @@ static EXTENDED_HELP: &str = " -@, --extended list each file's extended
/// All the information needed to display the help text, which depends /// All the information needed to display the help text, which depends
/// on which features are enabled and whether the user only wants to /// on which features are enabled and whether the user only wants to
/// see one sections help. /// see one sections help.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct HelpString; pub struct HelpString;
impl HelpString { impl HelpString {

View File

@ -216,7 +216,7 @@ pub mod test {
use crate::options::parser::{Arg, MatchedFlags}; use crate::options::parser::{Arg, MatchedFlags};
use std::ffi::OsStr; use std::ffi::OsStr;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum Strictnesses { pub enum Strictnesses {
Last, Last,
Complain, Complain,
@ -228,14 +228,14 @@ pub mod test {
/// both, then both should resolve to the same result. /// both, then both should resolve to the same result.
/// ///
/// It returns a vector with one or two elements in. /// It returns a vector with one or two elements in.
/// These elements can then be tested with assert_eq or what have you. /// These elements can then be tested with `assert_eq` or what have you.
pub fn parse_for_test<T, F>(inputs: &[&str], args: &'static [&'static Arg], strictnesses: Strictnesses, get: F) -> Vec<T> pub fn parse_for_test<T, F>(inputs: &[&str], args: &'static [&'static Arg], strictnesses: Strictnesses, get: F) -> Vec<T>
where F: Fn(&MatchedFlags<'_>) -> T where F: Fn(&MatchedFlags<'_>) -> T
{ {
use self::Strictnesses::*; use self::Strictnesses::*;
use crate::options::parser::{Args, Strictness}; use crate::options::parser::{Args, Strictness};
let bits = inputs.into_iter().map(OsStr::new).collect::<Vec<_>>(); let bits = inputs.iter().map(OsStr::new).collect::<Vec<_>>();
let mut result = Vec::new(); let mut result = Vec::new();
if strictnesses == Last || strictnesses == Both { if strictnesses == Last || strictnesses == Both {

View File

@ -52,7 +52,7 @@ pub type Values = &'static [&'static str];
/// A **flag** is either of the two argument types, because they have to /// A **flag** is either of the two argument types, because they have to
/// be in the same array together. /// be in the same array together.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Flag { pub enum Flag {
Short(ShortArg), Short(ShortArg),
Long(LongArg), Long(LongArg),
@ -77,7 +77,7 @@ impl fmt::Display for Flag {
} }
/// Whether redundant arguments should be considered a problem. /// Whether redundant arguments should be considered a problem.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Strictness { pub enum Strictness {
/// Throw an error when an argument doesnt do anything, either because /// Throw an error when an argument doesnt do anything, either because
@ -91,7 +91,7 @@ pub enum Strictness {
/// Whether a flag takes a value. This is applicable to both long and short /// Whether a flag takes a value. This is applicable to both long and short
/// arguments. /// arguments.
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TakesValue { pub enum TakesValue {
/// This flag has to be followed by a value. /// This flag has to be followed by a value.
@ -108,7 +108,7 @@ pub enum TakesValue {
/// An **argument** can be matched by one of the users input strings. /// An **argument** can be matched by one of the users input strings.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct Arg { pub struct Arg {
/// The short argument that matches it, if any. /// The short argument that matches it, if any.
@ -136,7 +136,7 @@ impl fmt::Display for Arg {
/// Literally just several args. /// Literally just several args.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Args(pub &'static [&'static Arg]); pub struct Args(pub &'static [&'static Arg]);
impl Args { impl Args {
@ -340,7 +340,7 @@ impl Args {
/// The **matches** are the result of parsing the users command-line strings. /// The **matches** are the result of parsing the users command-line strings.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Matches<'args> { pub struct Matches<'args> {
/// The flags that were parsed from the users input. /// The flags that were parsed from the users input.
@ -351,7 +351,7 @@ pub struct Matches<'args> {
pub frees: Vec<&'args OsStr>, pub frees: Vec<&'args OsStr>,
} }
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct MatchedFlags<'args> { pub struct MatchedFlags<'args> {
/// The individual flags from the users input, in the order they were /// The individual flags from the users input, in the order they were
@ -462,7 +462,7 @@ impl<'a> MatchedFlags<'a> {
/// A problem with the users input that meant it couldnt be parsed into a /// A problem with the users input that meant it couldnt be parsed into a
/// coherent list of arguments. /// coherent list of arguments.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub enum ParseError { pub enum ParseError {
/// A flag that has to take a value was not given one. /// A flag that has to take a value was not given one.
@ -743,6 +743,6 @@ mod matches_test {
fn no_count() { fn no_count() {
let flags = MatchedFlags { flags: Vec::new(), strictness: Strictness::UseLastArguments }; let flags = MatchedFlags { flags: Vec::new(), strictness: Strictness::UseLastArguments };
assert_eq!(flags.has(&COUNT).unwrap(), false); assert!(!flags.has(&COUNT).unwrap());
} }
} }

View File

@ -130,18 +130,18 @@ mod terminal_test {
impl MockVars { impl MockVars {
fn empty() -> MockVars { fn empty() -> MockVars {
return MockVars { MockVars {
ls: "", ls: "",
exa: "", exa: "",
no_color: "", no_color: "",
}; }
} }
fn with_no_color() -> MockVars { fn with_no_color() -> MockVars {
return MockVars { MockVars {
ls: "", ls: "",
exa: "", exa: "",
no_color: "true", no_color: "true",
}; }
} }
} }

View File

@ -8,7 +8,7 @@ use crate::options::flags;
use crate::options::parser::MatchedFlags; use crate::options::parser::MatchedFlags;
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct VersionString; pub struct VersionString;
// There were options here once, but there arent anymore! // There were options here once, but there arent anymore!

View File

@ -378,7 +378,7 @@ mod test {
($name:ident: $type:ident <- $inputs:expr; $stricts:expr => err $result:expr) => { ($name:ident: $type:ident <- $inputs:expr; $stricts:expr => err $result:expr) => {
/// Special macro for testing Err results. /// Special macro for testing Err results.
/// This is needed because sometimes the Ok type doesnt implement PartialEq. /// This is needed because sometimes the Ok type doesnt implement `PartialEq`.
#[test] #[test]
fn $name() { fn $name() {
for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) { for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {
@ -389,7 +389,7 @@ mod test {
($name:ident: $type:ident <- $inputs:expr; $stricts:expr => like $pat:pat) => { ($name:ident: $type:ident <- $inputs:expr; $stricts:expr => like $pat:pat) => {
/// More general macro for testing against a pattern. /// More general macro for testing against a pattern.
/// Instead of using PartialEq, this just tests if it matches a pat. /// Instead of using `PartialEq`, this just tests if it matches a pat.
#[test] #[test]
fn $name() { fn $name() {
for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) { for result in parse_for_test($inputs.as_ref(), TEST_ARGS, $stricts, |mf| $type::deduce(mf)) {

View File

@ -77,11 +77,9 @@ impl TextCell {
/// ///
/// This method allocates a `String` to hold the spaces. /// This method allocates a `String` to hold the spaces.
pub fn add_spaces(&mut self, count: usize) { pub fn add_spaces(&mut self, count: usize) {
use std::iter::repeat;
(*self.width) += count; (*self.width) += count;
let spaces: String = repeat(' ').take(count).collect(); let spaces: String = " ".repeat(count);
self.contents.0.push(Style::default().paint(spaces)); self.contents.0.push(Style::default().paint(spaces));
} }
@ -193,7 +191,7 @@ impl TextCellContents {
/// ///
/// It has `From` impls that convert an input string or fixed with to values /// It has `From` impls that convert an input string or fixed with to values
/// of this type, and will `Deref` to the contained `usize` value. /// of this type, and will `Deref` to the contained `usize` value.
#[derive(PartialEq, Debug, Clone, Copy, Default)] #[derive(PartialEq, Eq, Debug, Clone, Copy, Default)]
pub struct DisplayWidth(usize); pub struct DisplayWidth(usize);
impl<'a> From<&'a str> for DisplayWidth { impl<'a> From<&'a str> for DisplayWidth {

View File

@ -91,7 +91,7 @@ use crate::theme::Theme;
/// ///
/// Almost all the heavy lifting is done in a Table object, which handles the /// Almost all the heavy lifting is done in a Table object, which handles the
/// columns for each row. /// columns for each row.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Options { pub struct Options {
/// Options specific to drawing a table. /// Options specific to drawing a table.
@ -161,7 +161,7 @@ impl<'a> Render<'a> {
(None, _) => {/* Keep Git how it is */}, (None, _) => {/* Keep Git how it is */},
} }
let mut table = Table::new(table, self.git, &self.theme); let mut table = Table::new(table, self.git, self.theme);
if self.opts.header { if self.opts.header {
let header = table.header_row(); let header = table.header_row();

View File

@ -54,7 +54,7 @@ enum LinkStyle {
/// Whether to append file class characters to the file names. /// Whether to append file class characters to the file names.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum Classify { pub enum Classify {
/// Just display the file names, without any characters. /// Just display the file names, without any characters.
@ -73,7 +73,7 @@ impl Default for Classify {
/// Whether and how to show icons. /// Whether and how to show icons.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum ShowIcons { pub enum ShowIcons {
/// Dont show icons at all. /// Dont show icons at all.

View File

@ -8,7 +8,7 @@ use crate::output::file_name::Options as FileStyle;
use crate::theme::Theme; use crate::theme::Theme;
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct Options { pub struct Options {
pub across: bool, pub across: bool,
} }

View File

@ -18,7 +18,7 @@ use crate::output::tree::{TreeParams, TreeDepth};
use crate::theme::Theme; use crate::theme::Theme;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Options { pub struct Options {
pub grid: GridOptions, pub grid: GridOptions,
pub details: DetailsOptions, pub details: DetailsOptions,
@ -39,7 +39,7 @@ impl Options {
/// small directory of four files in four columns, the files just look spaced /// small directory of four files in four columns, the files just look spaced
/// out and its harder to see whats going on. So it can be enabled just for /// out and its harder to see whats going on. So it can be enabled just for
/// larger directory listings. /// larger directory listings.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum RowThreshold { pub enum RowThreshold {
/// Only use grid-details view if it would result in at least this many /// Only use grid-details view if it would result in at least this many
@ -202,7 +202,7 @@ impl<'a> Render<'a> {
(None, _) => {/* Keep Git how it is */}, (None, _) => {/* Keep Git how it is */},
} }
let mut table = Table::new(options, self.git, &self.theme); let mut table = Table::new(options, self.git, self.theme);
let mut rows = Vec::new(); let mut rows = Vec::new();
if self.details.header { if self.details.header {

View File

@ -26,7 +26,7 @@ pub struct View {
/// The **mode** is the “type” of output. /// The **mode** is the “type” of output.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub enum Mode { pub enum Mode {
Grid(grid::Options), Grid(grid::Options),
@ -37,7 +37,7 @@ pub enum Mode {
/// The width of the terminal requested by the user. /// The width of the terminal requested by the user.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TerminalWidth { pub enum TerminalWidth {
/// The user requested this specific number of columns. /// The user requested this specific number of columns.

View File

@ -43,7 +43,7 @@ pub mod test {
let blox = f::Blocks::None; let blox = f::Blocks::None;
let expected = TextCell::blank(Green.italic()); let expected = TextCell::blank(Green.italic());
assert_eq!(expected, blox.render(&TestColours).into()); assert_eq!(expected, blox.render(&TestColours));
} }
@ -52,6 +52,6 @@ pub mod test {
let blox = f::Blocks::Some(3005); let blox = f::Blocks::Some(3005);
let expected = TextCell::paint_str(Red.blink(), "3005"); let expected = TextCell::paint_str(Red.blink(), "3005");
assert_eq!(expected, blox.render(&TestColours).into()); assert_eq!(expected, blox.render(&TestColours));
} }
} }

View File

@ -85,7 +85,7 @@ pub mod test {
].into(), ].into(),
}; };
assert_eq!(expected, stati.render(&TestColours).into()) assert_eq!(expected, stati.render(&TestColours))
} }
@ -104,6 +104,6 @@ pub mod test {
].into(), ].into(),
}; };
assert_eq!(expected, stati.render(&TestColours).into()) assert_eq!(expected, stati.render(&TestColours))
} }
} }

View File

@ -21,8 +21,8 @@ pub mod test {
#[test] #[test]
fn blocklessness() { fn blocklessness() {
let io = f::Inode(1414213); let io = f::Inode(1_414_213);
let expected = TextCell::paint_str(Cyan.underline(), "1414213"); let expected = TextCell::paint_str(Cyan.underline(), "1414213");
assert_eq!(expected, io.render(Cyan.underline()).into()); assert_eq!(expected, io.render(Cyan.underline()));
} }
} }

View File

@ -52,7 +52,7 @@ pub mod test {
contents: vec![ Blue.paint("1") ].into(), contents: vec![ Blue.paint("1") ].into(),
}; };
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into()); assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()));
} }
#[test] #[test]
@ -67,7 +67,7 @@ pub mod test {
contents: vec![ Blue.paint("3,005") ].into(), contents: vec![ Blue.paint("3,005") ].into(),
}; };
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into()); assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()));
} }
#[test] #[test]
@ -82,6 +82,6 @@ pub mod test {
contents: vec![ Blue.on(Red).paint("3,005") ].into(), contents: vec![ Blue.on(Red).paint("3,005") ].into(),
}; };
assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()).into()); assert_eq!(expected, stati.render(&TestColours, &locale::Numeric::english()));
} }
} }

View File

@ -6,7 +6,7 @@ use crate::output::cell::TextCell;
impl f::OctalPermissions { impl f::OctalPermissions {
fn bits_to_octal(r: bool, w: bool, x: bool) -> u8 { fn bits_to_octal(r: bool, w: bool, x: bool) -> u8 {
(r as u8) * 4 + (w as u8) * 2 + (x as u8) u8::from(r) * 4 + u8::from(w) * 2 + u8::from(x)
} }
pub fn render(&self, style: Style) -> TextCell { pub fn render(&self, style: Style) -> TextCell {
@ -40,7 +40,7 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "0755"); let expected = TextCell::paint_str(Purple.bold(), "0755");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
#[test] #[test]
@ -54,7 +54,7 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "0644"); let expected = TextCell::paint_str(Purple.bold(), "0644");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
#[test] #[test]
@ -68,7 +68,7 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "0600"); let expected = TextCell::paint_str(Purple.bold(), "0600");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
#[test] #[test]
@ -82,7 +82,7 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "4777"); let expected = TextCell::paint_str(Purple.bold(), "4777");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
@ -97,7 +97,7 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "2777"); let expected = TextCell::paint_str(Purple.bold(), "2777");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
#[test] #[test]
@ -111,6 +111,6 @@ pub mod test {
let octal = f::OctalPermissions{ permissions: bits }; let octal = f::OctalPermissions{ permissions: bits };
let expected = TextCell::paint_str(Purple.bold(), "1777"); let expected = TextCell::paint_str(Purple.bold(), "1777");
assert_eq!(expected, octal.render(Purple.bold()).into()); assert_eq!(expected, octal.render(Purple.bold()));
} }
} }

View File

@ -153,7 +153,7 @@ pub mod test {
#[test] #[test]
fn file_bytes() { fn file_bytes() {
let directory = f::Size::Some(1048576); let directory = f::Size::Some(1_048_576);
let expected = TextCell { let expected = TextCell {
width: DisplayWidth::from(9), width: DisplayWidth::from(9),
contents: vec![ contents: vec![

View File

@ -21,7 +21,7 @@ use crate::theme::Theme;
/// Options for displaying a table. /// Options for displaying a table.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Options { pub struct Options {
pub size_format: SizeFormat, pub size_format: SizeFormat,
pub time_format: TimeFormat, pub time_format: TimeFormat,
@ -31,7 +31,7 @@ pub struct Options {
/// Extra columns to display in the table. /// Extra columns to display in the table.
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub struct Columns { pub struct Columns {
/// At least one of these timestamps will be shown. /// At least one of these timestamps will be shown.
@ -200,8 +200,8 @@ impl Column {
/// Formatting options for file sizes. /// Formatting options for file sizes.
#[allow(clippy::pub_enum_variant_names)] #[allow(clippy::enum_variant_names)]
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SizeFormat { pub enum SizeFormat {
/// Format the file size using **decimal** prefixes, such as “kilo”, /// Format the file size using **decimal** prefixes, such as “kilo”,
@ -217,7 +217,7 @@ pub enum SizeFormat {
} }
/// Formatting options for user and group. /// Formatting options for user and group.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum UserFormat { pub enum UserFormat {
/// The UID / GID /// The UID / GID
Numeric, Numeric,
@ -234,7 +234,7 @@ impl Default for SizeFormat {
/// The types of a files time fields. These three fields are standard /// The types of a files time fields. These three fields are standard
/// across most (all?) operating systems. /// across most (all?) operating systems.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TimeType { pub enum TimeType {
/// The files modified time (`st_mtime`). /// The files modified time (`st_mtime`).
@ -269,7 +269,7 @@ impl TimeType {
/// ///
/// There should always be at least one of these — theres no way to disable /// There should always be at least one of these — theres no way to disable
/// the time columns entirely (yet). /// the time columns entirely (yet).
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
pub struct TimeTypes { pub struct TimeTypes {
pub modified: bool, pub modified: bool,
@ -347,7 +347,7 @@ fn determine_time_zone() -> TZResult<TimeZone> {
} else { } else {
format!("/usr/share/zoneinfo/{}", { format!("/usr/share/zoneinfo/{}", {
if file.starts_with(':') { if file.starts_with(':') {
file.replacen(":", "", 1) file.replacen(':', "", 1)
} else { } else {
file file
} }

View File

@ -25,7 +25,7 @@ use unicode_width::UnicodeWidthStr;
/// ///
/// Currently exa does not support *custom* styles, where the user enters a /// Currently exa does not support *custom* styles, where the user enters a
/// format string in an environment variable or something. Just these four. /// format string in an environment variable or something. Just these four.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TimeFormat { pub enum TimeFormat {
/// The **default format** uses the users locale to print month names, /// The **default format** uses the users locale to print month names,
@ -87,7 +87,7 @@ fn default_zoned(time: SystemTime, zone: &TimeZone) -> String {
} }
fn get_dateformat(date: &LocalDateTime) -> &'static DateFormat<'static> { fn get_dateformat(date: &LocalDateTime) -> &'static DateFormat<'static> {
match (is_recent(&date), *MAXIMUM_MONTH_WIDTH) { match (is_recent(date), *MAXIMUM_MONTH_WIDTH) {
(true, 4) => &FOUR_WIDE_DATE_TIME, (true, 4) => &FOUR_WIDE_DATE_TIME,
(true, 5) => &FIVE_WIDE_DATE_TIME, (true, 5) => &FIVE_WIDE_DATE_TIME,
(true, _) => &OTHER_WIDE_DATE_TIME, (true, _) => &OTHER_WIDE_DATE_TIME,

View File

@ -39,7 +39,7 @@
//! each directory) //! each directory)
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum TreePart { pub enum TreePart {
/// Rightmost column, *not* the last in the directory. /// Rightmost column, *not* the last in the directory.
@ -253,19 +253,19 @@ mod iter_test {
#[test] #[test]
fn test_iteration() { fn test_iteration() {
let foos = &[ "first", "middle", "last" ]; let foos = &[ "first", "middle", "last" ];
let mut iter = TreeDepth::root().iterate_over(foos.into_iter()); let mut iter = TreeDepth::root().iterate_over(foos.iter());
let next = iter.next().unwrap(); let next = iter.next().unwrap();
assert_eq!(&"first", next.1); assert_eq!(&"first", next.1);
assert_eq!(false, next.0.last); assert!(!next.0.last);
let next = iter.next().unwrap(); let next = iter.next().unwrap();
assert_eq!(&"middle", next.1); assert_eq!(&"middle", next.1);
assert_eq!(false, next.0.last); assert!(!next.0.last);
let next = iter.next().unwrap(); let next = iter.next().unwrap();
assert_eq!(&"last", next.1); assert_eq!(&"last", next.1);
assert_eq!(true, next.0.last); assert!(next.0.last);
assert!(iter.next().is_none()); assert!(iter.next().is_none());
} }
@ -273,7 +273,7 @@ mod iter_test {
#[test] #[test]
fn test_empty() { fn test_empty() {
let nothing: &[usize] = &[]; let nothing: &[usize] = &[];
let mut iter = TreeDepth::root().iterate_over(nothing.into_iter()); let mut iter = TreeDepth::root().iterate_over(nothing.iter());
assert!(iter.next().is_none()); assert!(iter.next().is_none());
} }
} }

View File

@ -14,7 +14,7 @@ pub use self::lsc::LSColors;
mod default_theme; mod default_theme;
#[derive(PartialEq, Debug)] #[derive(PartialEq, Eq, Debug)]
pub struct Options { pub struct Options {
pub use_colours: UseColours, pub use_colours: UseColours,
@ -31,7 +31,7 @@ pub struct Options {
/// Turning them on when output is going to, say, a pipe, would make programs /// Turning them on when output is going to, say, a pipe, would make programs
/// such as `grep` or `more` not work properly. So the `Automatic` mode does /// such as `grep` or `more` not work properly. So the `Automatic` mode does
/// this check and only displays colours when they can be truly appreciated. /// this check and only displays colours when they can be truly appreciated.
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum UseColours { pub enum UseColours {
/// Display them even when output isnt going to a terminal. /// Display them even when output isnt going to a terminal.
@ -44,13 +44,13 @@ pub enum UseColours {
Never, Never,
} }
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum ColourScale { pub enum ColourScale {
Fixed, Fixed,
Gradient, Gradient,
} }
#[derive(PartialEq, Debug, Default)] #[derive(PartialEq, Eq, Debug, Default)]
pub struct Definitions { pub struct Definitions {
pub ls: Option<String>, pub ls: Option<String>,
pub exa: Option<String>, pub exa: Option<String>,
@ -262,11 +262,11 @@ impl render::SizeColours for Theme {
use number_prefix::Prefix::*; use number_prefix::Prefix::*;
match prefix { match prefix {
None => self.ui.size.number_byte, Some(Kilo | Kibi) => self.ui.size.number_kilo,
Some(Kilo) | Some(Kibi) => self.ui.size.number_kilo, Some(Mega | Mebi) => self.ui.size.number_mega,
Some(Mega) | Some(Mebi) => self.ui.size.number_mega, Some(Giga | Gibi) => self.ui.size.number_giga,
Some(Giga) | Some(Gibi) => self.ui.size.number_giga, Some(_) => self.ui.size.number_huge,
Some(_) => self.ui.size.number_huge, None => self.ui.size.number_byte,
} }
} }
@ -274,11 +274,11 @@ impl render::SizeColours for Theme {
use number_prefix::Prefix::*; use number_prefix::Prefix::*;
match prefix { match prefix {
None => self.ui.size.unit_byte, Some(Kilo | Kibi) => self.ui.size.unit_kilo,
Some(Kilo) | Some(Kibi) => self.ui.size.unit_kilo, Some(Mega | Mebi) => self.ui.size.unit_mega,
Some(Mega) | Some(Mebi) => self.ui.size.unit_mega, Some(Giga | Gibi) => self.ui.size.unit_giga,
Some(Giga) | Some(Gibi) => self.ui.size.unit_giga, Some(_) => self.ui.size.unit_huge,
Some(_) => self.ui.size.unit_huge, None => self.ui.size.unit_byte,
} }
} }