summaryrefslogtreecommitdiffstats
path: root/src/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/dir_action.rs20
-rw-r--r--src/fs/fields.rs19
-rw-r--r--src/fs/file.rs11
3 files changed, 29 insertions, 21 deletions
diff --git a/src/fs/dir_action.rs b/src/fs/dir_action.rs
index d72db88..26e78d3 100644
--- a/src/fs/dir_action.rs
+++ b/src/fs/dir_action.rs
@@ -39,19 +39,19 @@ pub enum DirAction {
impl DirAction {
/// Gets the recurse options, if this dir action has any.
- pub fn recurse_options(&self) -> Option<RecurseOptions> {
- match *self {
- Self::Recurse(o) => Some(o),
- _ => None,
+ pub fn recurse_options(self) -> Option<RecurseOptions> {
+ match self {
+ Self::Recurse(o) => Some(o),
+ _ => None,
}
}
/// Whether to treat directories as regular files or not.
- pub fn treat_dirs_as_files(&self) -> bool {
- match *self {
+ pub fn treat_dirs_as_files(self) -> bool {
+ match self {
Self::AsFile => true,
Self::Recurse(o) => o.tree,
- _ => false,
+ _ => false,
}
}
}
@@ -73,10 +73,10 @@ pub struct RecurseOptions {
impl RecurseOptions {
/// Returns whether a directory of the given depth would be too deep.
- pub fn is_too_deep(&self, depth: usize) -> bool {
+ pub fn is_too_deep(self, depth: usize) -> bool {
match self.max_depth {
- None => false,
- Some(d) => d <= depth
+ None => false,
+ Some(d) => d <= depth
}
}
}
diff --git a/src/fs/fields.rs b/src/fs/fields.rs
index 28c022d..397fd21 100644
--- a/src/fs/fields.rs
+++ b/src/fs/fields.rs
@@ -43,19 +43,20 @@ pub type uid_t = u32;
/// regular file. (See the `filetype` module for those checks.)
///
/// Its ordering is used when sorting by type.
-#[derive(PartialEq, Eq, PartialOrd, Ord)]
+#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
pub enum Type {
Directory, File, Link, Pipe, Socket, CharDevice, BlockDevice, Special,
}
impl Type {
- pub fn is_regular_file(&self) -> bool {
- matches!(*self, Self::File)
+ pub fn is_regular_file(self) -> bool {
+ matches!(self, Self::File)
}
}
/// The file’s Unix permission bitfield, with one entry per bit.
+#[derive(Copy, Clone)]
pub struct Permissions {
pub user_read: bool,
pub user_write: bool,
@@ -77,6 +78,7 @@ pub struct Permissions {
/// The three pieces of information that are displayed as a single column in
/// the details view. These values are fused together to make the output a
/// little more compressed.
+#[derive(Copy, Clone)]
pub struct PermissionsPlus {
pub file_type: Type,
pub permissions: Permissions,
@@ -85,6 +87,7 @@ pub struct PermissionsPlus {
/// The permissions encoded as octal values
+#[derive(Copy, Clone)]
pub struct OctalPermissions {
pub permissions: Permissions,
}
@@ -95,6 +98,7 @@ pub struct OctalPermissions {
/// multiple directories. However, it’s rare (but occasionally useful!) for a
/// regular file to have a link count greater than 1, so we highlight the
/// block count specifically for this case.
+#[derive(Copy, Clone)]
pub struct Links {
/// The actual link count.
@@ -108,10 +112,12 @@ pub struct Links {
/// A file’s inode. Every directory entry on a Unix filesystem has an inode,
/// including directories and links, so this is applicable to everything exa
/// can deal with.
+#[derive(Copy, Clone)]
pub struct Inode(pub ino_t);
/// The number of blocks that a file takes up on the filesystem, if any.
+#[derive(Copy, Clone)]
pub enum Blocks {
/// This file has the given number of blocks.
@@ -124,14 +130,17 @@ pub enum Blocks {
/// The ID of the user that owns a file. This will only ever be a number;
/// looking up the username is done in the `display` module.
+#[derive(Copy, Clone)]
pub struct User(pub uid_t);
/// The ID of the group that a file belongs to.
+#[derive(Copy, Clone)]
pub struct Group(pub gid_t);
/// A file’s size, in bytes. This is usually formatted by the `number_prefix`
/// crate into something human-readable.
+#[derive(Copy, Clone)]
pub enum Size {
/// This file has a defined size.
@@ -162,6 +171,7 @@ pub enum Size {
/// You can see what these device numbers mean:
/// - http://www.lanana.org/docs/device-list/
/// - http://www.lanana.org/docs/device-list/devices-2.6+.txt
+#[derive(Copy, Clone)]
pub struct DeviceIDs {
pub major: u8,
pub minor: u8,
@@ -179,7 +189,7 @@ pub struct Time {
/// A file’s 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
/// this enum.
-#[derive(PartialEq)]
+#[derive(PartialEq, Copy, Clone)]
pub enum GitStatus {
/// This file hasn’t changed since the last commit.
@@ -211,6 +221,7 @@ pub enum GitStatus {
/// A file’s complete Git status. It’s possible to make changes to a file, add
/// it to the staging area, then make *more* changes, so we need to list each
/// file’s status for both of these.
+#[derive(Copy, Clone)]
pub struct Git {
pub staged: GitStatus,
pub unstaged: GitStatus,
diff --git a/src/fs/file.rs b/src/fs/file.rs
index c22b815..5657588 100644
--- a/src/fs/file.rs
+++ b/src/fs/file.rs
@@ -417,9 +417,9 @@ impl<'dir> File<'dir> {
///
/// This will always return `false` if the file has no extension.
pub fn extension_is_one_of(&self, choices: &[&str]) -> bool {
- match self.ext {
- Some(ref ext) => choices.contains(&&ext[..]),
- None => false,
+ match &self.ext {
+ Some(ext) => choices.contains(&&ext[..]),
+ None => false,
}
}
@@ -463,10 +463,7 @@ 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.
pub fn is_broken(&self) -> bool {
- match *self {
- FileTarget::Ok(_) => false,
- FileTarget::Broken(_) | FileTarget::Err(_) => true,
- }
+ matches!(self, Self::Broken(_) | Self::Err(_))
}
}