From 08e77034a78f038fc82a2a9a50736db7b790f4ba Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 30 Apr 2025 15:15:51 +0200 Subject: [PATCH] refactor: add Justfile; fix some clippy lints --- Justfile | 35 +++++++++++++++++++++++++++++++++++ backup/src/delta.rs | 9 +-------- backup/src/lib.rs | 4 ++-- backup/src/state.rs | 14 ++------------ 4 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 Justfile diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..511d61f --- /dev/null +++ b/Justfile @@ -0,0 +1,35 @@ +[group('build')] +build pkg: + cargo build --package {{ pkg }} +alias b := build + +[group('build')] +build-all: + cargo build --workspace +alias ba := build-all + +[group('test')] +test pkg: + cargo test --package {{ pkg }} +alias t := test + +[group('test')] +test-all: + cargo test --workspace +alias ta := test-all + +[group('check')] +check pkg: + cargo fmt --check --package {{ pkg }} + cargo clippy --package {{ pkg }} -- \ + --no-deps \ + --deny 'clippy::all' +alias c := check + +[group('check')] +check-all: + cargo fmt --check --all + cargo clippy --all -- \ + --no-deps \ + --deny 'clippy::all' +alias ca := check-all diff --git a/backup/src/delta.rs b/backup/src/delta.rs index 1260b43..6bdff88 100644 --- a/backup/src/delta.rs +++ b/backup/src/delta.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use super::State; /// Represents the changes relative to the previous backup -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct Delta { /// What files were added/modified in each part of the tarball. pub added: State, @@ -17,13 +17,6 @@ pub struct Delta { } impl Delta { - pub fn new() -> Self { - Self { - added: State::new(), - removed: State::new(), - } - } - /// Returns whether the delta is empty by checking whether both its added and removed state /// return true for their `is_empty`. #[allow(dead_code)] diff --git a/backup/src/lib.rs b/backup/src/lib.rs index f61773d..6569f83 100644 --- a/backup/src/lib.rs +++ b/backup/src/lib.rs @@ -129,7 +129,7 @@ impl Backup { let enc = GzEncoder::new(tar_gz, Compression::default()); let mut ar = tar::Builder::new(enc); - let mut delta = Delta::new(); + let mut delta = Delta::default(); for (dir_in_tar, src_dir) in dirs { let mut added_files: HashSet = HashSet::new(); @@ -187,7 +187,7 @@ impl Backup { let enc = GzEncoder::new(tar_gz, Compression::default()); let mut ar = tar::Builder::new(enc); - let mut delta = Delta::new(); + let mut delta = Delta::default(); for (dir_in_tar, src_dir) in dirs { let mut all_files: HashSet = HashSet::new(); diff --git a/backup/src/state.rs b/backup/src/state.rs index c6a992f..c0f66b9 100644 --- a/backup/src/state.rs +++ b/backup/src/state.rs @@ -11,14 +11,10 @@ use crate::Delta; /// Struct that represents a current state for a backup. This struct acts as a smart pointer around /// a HashMap. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] pub struct State(HashMap>); impl State { - pub fn new() -> Self { - State(HashMap::new()) - } - /// Apply the delta to the current state. pub fn apply(&mut self, delta: &Delta) { // First we add new files, then we remove the old ones @@ -61,7 +57,7 @@ where T::Item: Borrow, { fn from(deltas: T) -> Self { - let mut state = State::new(); + let mut state = State::default(); for delta in deltas { state.apply(delta.borrow()); @@ -90,9 +86,3 @@ impl DerefMut for State { &mut self.0 } } - -impl Default for State { - fn default() -> Self { - Self::new() - } -}