summaryrefslogtreecommitdiffstats
path: root/src/fs/fields.rs
diff options
context:
space:
mode:
authorBenjamin Sago <ogham@bsago.me>2020-10-10 15:30:19 +0100
committerBenjamin Sago <ogham@bsago.me>2020-10-10 15:30:19 +0100
commitf0c139ca682178e5cf4e735c0d7621719e73f6a0 (patch)
tree466fe7270a5dc7360f494a0e5c8c9b24d576c0cf /src/fs/fields.rs
parent70a30ed683ecc88304c6b2d66b6d34d61a1dd072 (diff)
Better referencing
This commit makes changes to the way variables are referenced: • Make types Copy when possible • Make methods take `self` instead of `&self` where possible (trivially_copy_pass_by_ref) • Remove unnecessary borrowing (needless_ref) • Remove unnecessary cloning (clone_on_copy) • Remove `ref` from match arms where possible (new Rust match ergonomics)
Diffstat (limited to 'src/fs/fields.rs')
-rw-r--r--src/fs/fields.rs19
1 files changed, 15 insertions, 4 deletions
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,