refactor: add Justfile; fix some clippy lints

This commit is contained in:
Jef Roosens 2025-04-30 15:15:51 +02:00
parent abafd9a28c
commit 08e77034a7
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
4 changed files with 40 additions and 22 deletions

View file

@ -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)]

View file

@ -129,7 +129,7 @@ impl<T: Clone> Backup<T> {
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<PathBuf> = HashSet::new();
@ -187,7 +187,7 @@ impl<T: Clone> Backup<T> {
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<PathBuf> = HashSet::new();

View file

@ -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<PathBuf, HashSet<PathBuf>>);
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<Delta>,
{
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()
}
}