浏览代码

style: update formatting

Signed-off-by: Christina Sørensen <ces@fem.gg>
Christina Sørensen 8 月之前
父节点
当前提交
fe82442933

+ 6 - 3
src/fs/dir.rs

@@ -50,7 +50,8 @@ impl Dir {
 
     /// Produce an iterator of IO results of trying to read all the files in
     /// this directory.
-    #[must_use] pub fn files<'dir, 'ig>(
+    #[must_use]
+    pub fn files<'dir, 'ig>(
         &'dir self,
         dots: DotFilter,
         git: Option<&'ig GitCache>,
@@ -71,12 +72,14 @@ impl Dir {
     }
 
     /// Whether this directory contains a file with the given path.
-    #[must_use] pub fn contains(&self, path: &Path) -> bool {
+    #[must_use]
+    pub fn contains(&self, path: &Path) -> bool {
         self.contents.iter().any(|p| p.path().as_path() == path)
     }
 
     /// Append a path onto the path specified by this directory.
-    #[must_use] pub fn join(&self, child: &Path) -> PathBuf {
+    #[must_use]
+    pub fn join(&self, child: &Path) -> PathBuf {
         self.path.join(child)
     }
 }

+ 6 - 3
src/fs/dir_action.rs

@@ -43,7 +43,8 @@ pub enum DirAction {
 
 impl DirAction {
     /// Gets the recurse options, if this dir action has any.
-    #[must_use] pub fn recurse_options(self) -> Option<RecurseOptions> {
+    #[must_use]
+    pub fn recurse_options(self) -> Option<RecurseOptions> {
         match self {
             Self::Recurse(o) => Some(o),
             _ => None,
@@ -51,7 +52,8 @@ impl DirAction {
     }
 
     /// Whether to treat directories as regular files or not.
-    #[must_use] pub fn treat_dirs_as_files(self) -> bool {
+    #[must_use]
+    pub fn treat_dirs_as_files(self) -> bool {
         match self {
             Self::AsFile => true,
             Self::Recurse(o) => o.tree,
@@ -74,7 +76,8 @@ pub struct RecurseOptions {
 
 impl RecurseOptions {
     /// Returns whether a directory of the given depth would be too deep.
-    #[must_use] pub fn is_too_deep(self, depth: usize) -> bool {
+    #[must_use]
+    pub fn is_too_deep(self, depth: usize) -> bool {
         match self.max_depth {
             None => false,
             Some(d) => d <= depth,

+ 6 - 3
src/fs/feature/git.rs

@@ -31,11 +31,13 @@ pub struct GitCache {
 }
 
 impl GitCache {
-    #[must_use] pub fn has_anything_for(&self, index: &Path) -> bool {
+    #[must_use]
+    pub fn has_anything_for(&self, index: &Path) -> bool {
         self.repos.iter().any(|e| e.has_path(index))
     }
 
-    #[must_use] pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
+    #[must_use]
+    pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
         self.repos
             .iter()
             .find(|repo| repo.has_path(index))
@@ -410,7 +412,8 @@ fn current_branch(repo: &git2::Repository) -> Option<String> {
 }
 
 impl f::SubdirGitRepo {
-    #[must_use] pub fn from_path(dir: &Path, status: bool) -> Self {
+    #[must_use]
+    pub fn from_path(dir: &Path, status: bool) -> Self {
         let path = &reorient(dir);
 
         if let Ok(repo) = git2::Repository::open(path) {

+ 2 - 1
src/fs/fields.rs

@@ -62,7 +62,8 @@ pub enum Type {
 }
 
 impl Type {
-    #[must_use] pub fn is_regular_file(self) -> bool {
+    #[must_use]
+    pub fn is_regular_file(self) -> bool {
         matches!(self, Self::File)
     }
 }

+ 8 - 4
src/fs/file.rs

@@ -209,18 +209,21 @@ impl<'dir> File<'dir> {
         file
     }
 
-    #[must_use] pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
+    #[must_use]
+    pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
         File::new_aa(parent_dir.path.clone(), parent_dir, ".", total_size)
     }
 
-    #[must_use] pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
+    #[must_use]
+    pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
         File::new_aa(path, parent_dir, "..", total_size)
     }
 
     /// A file’s name is derived from its string. This needs to handle directories
     /// such as `/` or `..`, which have no `file_name` component. So instead, just
     /// use the last component as the name.
-    #[must_use] pub fn filename(path: &Path) -> String {
+    #[must_use]
+    pub fn filename(path: &Path) -> String {
         if let Some(back) = path.components().next_back() {
             back.as_os_str().to_string_lossy().to_string()
         } else {
@@ -1016,7 +1019,8 @@ pub enum FileTarget<'dir> {
 impl<'dir> FileTarget<'dir> {
     /// Whether this link doesn’t lead to a file, for whatever reason. This
     /// gets used to determine how to highlight the link in grid views.
-    #[must_use] pub fn is_broken(&self) -> bool {
+    #[must_use]
+    pub fn is_broken(&self) -> bool {
         matches!(self, Self::Broken(_) | Self::Err(_))
     }
 }

+ 2 - 1
src/fs/filter.rs

@@ -365,7 +365,8 @@ impl IgnorePatterns {
     }
 
     /// Create a new empty set of patterns that matches nothing.
-    #[must_use] pub fn empty() -> Self {
+    #[must_use]
+    pub fn empty() -> Self {
         Self {
             patterns: Vec::new(),
         }

+ 4 - 2
src/fs/recursive_size.rs

@@ -37,7 +37,8 @@ impl RecursiveSize {
     /// assert_eq!(x.is_none(), false);
     /// ```
     #[inline]
-    #[must_use] pub const fn is_none(&self) -> bool {
+    #[must_use]
+    pub const fn is_none(&self) -> bool {
         matches!(*self, Self::None)
     }
 
@@ -53,7 +54,8 @@ impl RecursiveSize {
     /// assert_eq!(RecursiveSize::Some(2, 3).unwrap_bytes_or(1), 2);
     /// ```
     #[inline]
-    #[must_use] pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
+    #[must_use]
+    pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
         match self {
             Self::Some(bytes, _blocks) => bytes,
             _ => default,

+ 8 - 3
src/options/config.rs

@@ -5,7 +5,10 @@
 // SPDX-FileCopyrightText: 2014 Benjamin Sago
 // SPDX-License-Identifier: MIT
 use crate::theme::ThemeFileType as FileType;
-use crate::theme::{FileKinds, FileNameStyle, Git, GitRepo, IconStyle, Links, Permissions, SELinuxContext, SecurityContext, Size, UiStyles, Users};
+use crate::theme::{
+    FileKinds, FileNameStyle, Git, GitRepo, IconStyle, Links, Permissions, SELinuxContext,
+    SecurityContext, Size, UiStyles, Users,
+};
 use nu_ansi_term::{Color, Style};
 use serde::{Deserialize, Deserializer, Serialize};
 use serde_norway;
@@ -604,10 +607,12 @@ impl FromOverride<UiStylesOverride> for UiStyles {
     }
 }
 impl ThemeConfig {
-    #[must_use] pub fn from_path(path: PathBuf) -> Self {
+    #[must_use]
+    pub fn from_path(path: PathBuf) -> Self {
         ThemeConfig { location: path }
     }
-    #[must_use] pub fn to_theme(&self) -> Option<UiStyles> {
+    #[must_use]
+    pub fn to_theme(&self) -> Option<UiStyles> {
         let ui_styles_override: Option<UiStylesOverride> = {
             let file = std::fs::File::open(&self.location).ok()?;
             serde_norway::from_reader(&file).ok()

+ 2 - 1
src/options/error.rs

@@ -109,7 +109,8 @@ impl fmt::Display for OptionsError {
 impl OptionsError {
     /// Try to second-guess what the user was trying to do, depending on what
     /// went wrong.
-    #[must_use] pub fn suggestion(&self) -> Option<&'static str> {
+    #[must_use]
+    pub fn suggestion(&self) -> Option<&'static str> {
         // ‘ls -lt’ and ‘ls -ltr’ are common combinations
         match self {
             Self::BadArgument(time, r) if *time == &flags::TIME && r == "r" => {

+ 2 - 1
src/options/mod.rs

@@ -173,7 +173,8 @@ impl Options {
     /// Whether the View specified in this set of options includes a Git
     /// status column. It’s only worth trying to discover a repository if the
     /// results will end up being displayed.
-    #[must_use] pub fn should_scan_for_git(&self) -> bool {
+    #[must_use]
+    pub fn should_scan_for_git(&self) -> bool {
         if self.filter.git_ignore == GitIgnore::CheckAndIgnore {
             return true;
         }

+ 2 - 1
src/output/color_scale.rs

@@ -85,7 +85,8 @@ impl ColorScaleInformation {
         }
     }
 
-    #[must_use] pub fn adjust_style(&self, mut style: Style, value: f32, range: Option<Extremes>) -> Style {
+    #[must_use]
+    pub fn adjust_style(&self, mut style: Style, value: f32, range: Option<Extremes>) -> Style {
         if let (Some(fg), Some(range)) = (style.foreground, range) {
             let mut ratio = ((value - range.min) / (range.max - range.min)).clamp(0.0, 1.0);
             if ratio.is_nan() {

+ 6 - 3
src/output/details.rs

@@ -403,7 +403,8 @@ impl<'a> Render<'a> {
         }
     }
 
-    #[must_use] pub fn render_header(&self, header: TableRow) -> Row {
+    #[must_use]
+    pub fn render_header(&self, header: TableRow) -> Row {
         Row {
             tree: TreeParams::new(TreeDepth::root(), false),
             cells: Some(header),
@@ -442,7 +443,8 @@ impl<'a> Render<'a> {
         }
     }
 
-    #[must_use] pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
+    #[must_use]
+    pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
         TableIter {
             tree_trunk: TreeTrunk::default(),
             total_width: table.widths().total(),
@@ -452,7 +454,8 @@ impl<'a> Render<'a> {
         }
     }
 
-    #[must_use] pub fn iterate(&'a self, rows: Vec<Row>) -> Iter {
+    #[must_use]
+    pub fn iterate(&'a self, rows: Vec<Row>) -> Iter {
         Iter {
             tree_trunk: TreeTrunk::default(),
             inner: rows.into_iter(),

+ 10 - 5
src/output/file_name.rs

@@ -168,7 +168,8 @@ pub struct FileName<'a, 'dir, C> {
 impl<'a, 'dir, C> FileName<'a, 'dir, C> {
     /// Sets the flag on this file name to display link targets with an
     /// arrow followed by their path.
-    #[must_use] pub fn with_link_paths(mut self) -> Self {
+    #[must_use]
+    pub fn with_link_paths(mut self) -> Self {
         if !self.file.deref_links {
             self.link_style = LinkStyle::FullLinkPaths;
         }
@@ -177,7 +178,8 @@ impl<'a, 'dir, C> FileName<'a, 'dir, C> {
 
     /// Sets the flag on this file name to display mounted filesystem
     ///details.
-    #[must_use] pub fn with_mount_details(mut self, enable: bool) -> Self {
+    #[must_use]
+    pub fn with_mount_details(mut self, enable: bool) -> Self {
         self.mount_style = if enable {
             MountStyle::MountInfo
         } else {
@@ -194,7 +196,8 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
     /// This method returns some `TextCellContents`, rather than a `TextCell`,
     /// because for the last cell in a table, it doesn’t need to have its
     /// width calculated.
-    #[must_use] pub fn paint(&self) -> TextCellContents {
+    #[must_use]
+    pub fn paint(&self) -> TextCellContents {
         let mut bits = Vec::new();
         let (icon_override, filename_style_override) = match self.colours.style_override(self.file)
         {
@@ -461,7 +464,8 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
     /// depending on which “type” of file it appears to be — either from the
     /// class on the filesystem or from its name. (Or the broken link colour,
     /// if there’s nowhere else for that fact to be shown.)
-    #[must_use] pub fn style(&self) -> Style {
+    #[must_use]
+    pub fn style(&self) -> Style {
         if let LinkStyle::JustFilenames = self.link_style {
             if let Some(ref target) = self.target {
                 if target.is_broken() {
@@ -491,7 +495,8 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
     }
 
     /// For grid's use, to cover the case of hyperlink escape sequences
-    #[must_use] pub fn bare_utf8_width(&self) -> usize {
+    #[must_use]
+    pub fn bare_utf8_width(&self) -> usize {
         UnicodeWidthStr::width(self.file.name.as_str())
     }
 }

+ 2 - 1
src/output/grid.rs

@@ -19,7 +19,8 @@ pub struct Options {
 }
 
 impl Options {
-    #[must_use] pub fn direction(self) -> Direction {
+    #[must_use]
+    pub fn direction(self) -> Direction {
         if self.across {
             Direction::LeftToRight
         } else {

+ 2 - 1
src/output/grid_details.rs

@@ -29,7 +29,8 @@ pub struct Options {
 }
 
 impl Options {
-    #[must_use] pub fn to_details_options(&self) -> &DetailsOptions {
+    #[must_use]
+    pub fn to_details_options(&self) -> &DetailsOptions {
         &self.details
     }
 }

+ 2 - 1
src/output/mod.rs

@@ -55,7 +55,8 @@ pub enum TerminalWidth {
 }
 
 impl TerminalWidth {
-    #[must_use] pub fn actual_terminal_width(self) -> Option<usize> {
+    #[must_use]
+    pub fn actual_terminal_width(self) -> Option<usize> {
         // All of stdin, stdout, and stderr could not be connected to a
         // terminal, but we’re only interested in stdout because it’s
         // where the output goes.

+ 2 - 1
src/output/render/flags.rs

@@ -11,7 +11,8 @@ use crate::output::cell::TextCell;
 use crate::output::table::FlagsFormat;
 
 impl f::Flags {
-    #[must_use] pub fn render(self, style: Style, _format: FlagsFormat) -> TextCell {
+    #[must_use]
+    pub fn render(self, style: Style, _format: FlagsFormat) -> TextCell {
         TextCell::paint(style, "-".to_string())
     }
 }

+ 2 - 1
src/output/render/inode.rs

@@ -10,7 +10,8 @@ use crate::fs::fields as f;
 use crate::output::cell::TextCell;
 
 impl f::Inode {
-    #[must_use] pub fn render(self, style: Style) -> TextCell {
+    #[must_use]
+    pub fn render(self, style: Style) -> TextCell {
         TextCell::paint(style, self.0.to_string())
     }
 }

+ 20 - 10
src/output/table.rs

@@ -67,7 +67,8 @@ pub struct Columns {
 }
 
 impl Columns {
-    #[must_use] pub fn collect(&self, actually_enable_git: bool, git_repos: bool) -> Vec<Column> {
+    #[must_use]
+    pub fn collect(&self, actually_enable_git: bool, git_repos: bool) -> Vec<Column> {
         let mut columns = Vec::with_capacity(4);
 
         if self.inode {
@@ -185,7 +186,8 @@ pub enum Alignment {
 impl Column {
     /// Get the alignment this column should use.
     #[cfg(unix)]
-    #[must_use] pub fn alignment(self) -> Alignment {
+    #[must_use]
+    pub fn alignment(self) -> Alignment {
         #[allow(clippy::wildcard_in_or_patterns)]
         match self {
             Self::FileSize | Self::HardLinks | Self::Inode | Self::Blocksize | Self::GitStatus => {
@@ -205,7 +207,8 @@ impl Column {
 
     /// Get the text that should be printed at the top, when the user elects
     /// to have a header row printed.
-    #[must_use] pub fn header(self) -> &'static str {
+    #[must_use]
+    pub fn header(self) -> &'static str {
         match self {
             #[cfg(unix)]
             Self::Permissions => "Permissions",
@@ -288,7 +291,8 @@ pub enum TimeType {
 
 impl TimeType {
     /// Returns the text to use for a column’s heading in the columns output.
-    #[must_use] pub fn header(self) -> &'static str {
+    #[must_use]
+    pub fn header(self) -> &'static str {
         match self {
             Self::Modified => "Date Modified",
             Self::Changed => "Date Changed",
@@ -421,7 +425,8 @@ pub struct Row {
 }
 
 impl<'a> Table<'a> {
-    #[must_use] pub fn new(
+    #[must_use]
+    pub fn new(
         options: &'a Options,
         git: Option<&'a GitCache>,
         theme: &'a Theme,
@@ -449,11 +454,13 @@ impl<'a> Table<'a> {
         }
     }
 
-    #[must_use] pub fn widths(&self) -> &TableWidths {
+    #[must_use]
+    pub fn widths(&self) -> &TableWidths {
         &self.widths
     }
 
-    #[must_use] pub fn header_row(&self) -> Row {
+    #[must_use]
+    pub fn header_row(&self) -> Row {
         let cells = self
             .columns
             .iter()
@@ -591,7 +598,8 @@ impl<'a> Table<'a> {
         f::SubdirGitRepo::default()
     }
 
-    #[must_use] pub fn render(&self, row: Row) -> TextCell {
+    #[must_use]
+    pub fn render(&self, row: Row) -> TextCell {
         let mut cell = TextCell::default();
 
         let iter = row.cells.into_iter().zip(self.widths.iter()).enumerate();
@@ -628,7 +636,8 @@ impl Deref for TableWidths {
 }
 
 impl TableWidths {
-    #[must_use] pub fn zero(count: usize) -> Self {
+    #[must_use]
+    pub fn zero(count: usize) -> Self {
         Self(vec![0; count])
     }
 
@@ -638,7 +647,8 @@ impl TableWidths {
         }
     }
 
-    #[must_use] pub fn total(&self) -> usize {
+    #[must_use]
+    pub fn total(&self) -> usize {
         self.0.len() + self.0.iter().sum::<usize>()
     }
 }

+ 23 - 24
src/output/time.rs

@@ -62,7 +62,8 @@ pub enum TimeFormat {
 }
 
 impl TimeFormat {
-    #[must_use] pub fn format(self, time: &DateTime<FixedOffset>) -> String {
+    #[must_use]
+    pub fn format(self, time: &DateTime<FixedOffset>) -> String {
         #[rustfmt::skip]
         return match self {
             Self::DefaultFormat                 => default(time),
@@ -171,28 +172,26 @@ mod test {
     #[test]
     fn short_month_width_hindi() {
         let max_month_width = 4;
-        assert!(
-            [
-                "\u{091C}\u{0928}\u{0970}",                         // जन॰
-                "\u{092B}\u{093C}\u{0930}\u{0970}",                 // फ़र॰
-                "\u{092E}\u{093E}\u{0930}\u{094D}\u{091A}",         // मार्च
-                "\u{0905}\u{092A}\u{094D}\u{0930}\u{0948}\u{0932}", // अप्रैल
-                "\u{092E}\u{0908}",                                 // मई
-                "\u{091C}\u{0942}\u{0928}",                         // जून
-                "\u{091C}\u{0941}\u{0932}\u{0970}",                 // जुल॰
-                "\u{0905}\u{0917}\u{0970}",                         // अग॰
-                "\u{0938}\u{093F}\u{0924}\u{0970}",                 // सित॰
-                "\u{0905}\u{0915}\u{094D}\u{0924}\u{0942}\u{0970}", // अक्तू॰
-                "\u{0928}\u{0935}\u{0970}",                         // नव॰
-                "\u{0926}\u{093F}\u{0938}\u{0970}",                 // दिस॰
-            ]
-            .iter()
-            .map(|month| format!(
-                "{:<width$}",
-                month,
-                width = short_month_padding(max_month_width, month)
-            ))
-            .all(|string| UnicodeWidthStr::width(string.as_str()) == max_month_width)
-        );
+        assert!([
+            "\u{091C}\u{0928}\u{0970}",                         // जन॰
+            "\u{092B}\u{093C}\u{0930}\u{0970}",                 // फ़र॰
+            "\u{092E}\u{093E}\u{0930}\u{094D}\u{091A}",         // मार्च
+            "\u{0905}\u{092A}\u{094D}\u{0930}\u{0948}\u{0932}", // अप्रैल
+            "\u{092E}\u{0908}",                                 // मई
+            "\u{091C}\u{0942}\u{0928}",                         // जून
+            "\u{091C}\u{0941}\u{0932}\u{0970}",                 // जुल॰
+            "\u{0905}\u{0917}\u{0970}",                         // अग॰
+            "\u{0938}\u{093F}\u{0924}\u{0970}",                 // सित॰
+            "\u{0905}\u{0915}\u{094D}\u{0924}\u{0942}\u{0970}", // अक्तू॰
+            "\u{0928}\u{0935}\u{0970}",                         // नव॰
+            "\u{0926}\u{093F}\u{0938}\u{0970}",                 // दिस॰
+        ]
+        .iter()
+        .map(|month| format!(
+            "{:<width$}",
+            month,
+            width = short_month_padding(max_month_width, month)
+        ))
+        .all(|string| UnicodeWidthStr::width(string.as_str()) == max_month_width));
     }
 }

+ 6 - 2
src/theme/default_theme.rs

@@ -9,9 +9,13 @@ use nu_ansi_term::Style;
 use std::default::Default;
 
 use crate::output::color_scale::{ColorScaleMode, ColorScaleOptions};
-use crate::theme::ui_styles::{FileKinds, FileType, Git, GitRepo, Links, Permissions, SELinuxContext, SecurityContext, Size, UiStyles, Users};
+use crate::theme::ui_styles::{
+    FileKinds, FileType, Git, GitRepo, Links, Permissions, SELinuxContext, SecurityContext, Size,
+    UiStyles, Users,
+};
 impl UiStyles {
-    #[must_use] pub fn default_theme(scale: ColorScaleOptions) -> Self {
+    #[must_use]
+    pub fn default_theme(scale: ColorScaleOptions) -> Self {
         Self {
             size: Some(Size::colourful(scale)),
             ..Self::default()

+ 4 - 1
src/theme/lsc.rs

@@ -7,7 +7,10 @@
 use std::iter::Peekable;
 use std::ops::FnMut;
 
-use nu_ansi_term::Color::{Black, Blue, Cyan, DarkGray, Fixed, Green, LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, LightYellow, Purple, Red, Rgb, White, Yellow};
+use nu_ansi_term::Color::{
+    Black, Blue, Cyan, DarkGray, Fixed, Green, LightBlue, LightCyan, LightGray, LightGreen,
+    LightPurple, LightRed, LightYellow, Purple, Red, Rgb, White, Yellow,
+};
 use nu_ansi_term::{Color as Colour, Style};
 
 // Parsing the LS_COLORS environment variable into a map of names to Style values.

+ 2 - 1
src/theme/mod.rs

@@ -67,7 +67,8 @@ pub struct Theme {
 }
 
 impl Options {
-    #[must_use] pub fn to_theme(&self, isatty: bool) -> Theme {
+    #[must_use]
+    pub fn to_theme(&self, isatty: bool) -> Theme {
         if self.use_colours == UseColours::Never
             || (self.use_colours == UseColours::Automatic && !isatty)
         {

+ 6 - 2
src/theme/ui_styles.rs

@@ -5,7 +5,10 @@
 // SPDX-FileCopyrightText: 2014 Benjamin Sago
 // SPDX-License-Identifier: MIT
 use crate::theme::lsc::Pair;
-use nu_ansi_term::{Color::{Blue, Cyan, Green, Purple, Red, Yellow}, Style};
+use nu_ansi_term::{
+    Color::{Blue, Cyan, Green, Purple, Red, Yellow},
+    Style,
+};
 use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::default::Default;
@@ -382,7 +385,8 @@ pub struct FileType {
 }
 
 impl UiStyles {
-    #[must_use] pub fn plain() -> Self {
+    #[must_use]
+    pub fn plain() -> Self {
         Self {
             colourful: Some(false),