From a51ff3937d48f78ee48748f795bfc5539c0fddf3 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 11 Aug 2023 23:24:14 +0200 Subject: [PATCH] refactor: reorder imports --- src/backup/delta.rs | 7 ++--- src/backup/manager/config.rs | 4 +-- src/backup/manager/meta.rs | 15 ++++++----- src/backup/manager/mod.rs | 22 +++++++-------- src/backup/mod.rs | 25 ++++++++--------- src/backup/path.rs | 13 +++++---- src/backup/state.rs | 14 ++++++---- src/cli/backup.rs | 9 ++++--- src/cli/mod.rs | 52 +++++++++++++++++------------------- src/cli/run/mod.rs | 15 ++++++----- src/signals.rs | 15 ++++++----- src/stdin.rs | 6 +++-- 12 files changed, 106 insertions(+), 91 deletions(-) diff --git a/src/backup/delta.rs b/src/backup/delta.rs index 21f626c..1260b43 100644 --- a/src/backup/delta.rs +++ b/src/backup/delta.rs @@ -1,7 +1,8 @@ -use super::State; +use std::{borrow::Borrow, fmt}; + use serde::{Deserialize, Serialize}; -use std::borrow::Borrow; -use std::fmt; + +use super::State; /// Represents the changes relative to the previous backup #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/src/backup/manager/config.rs b/src/backup/manager/config.rs index 75af34e..a07be56 100644 --- a/src/backup/manager/config.rs +++ b/src/backup/manager/config.rs @@ -1,6 +1,4 @@ -use std::error::Error; -use std::fmt; -use std::str::FromStr; +use std::{error::Error, fmt, str::FromStr}; use serde::{Deserialize, Serialize}; diff --git a/src/backup/manager/meta.rs b/src/backup/manager/meta.rs index 4831f3f..a649764 100644 --- a/src/backup/manager/meta.rs +++ b/src/backup/manager/meta.rs @@ -1,10 +1,13 @@ -use super::{Manager, ManagerConfig}; +use std::{ + collections::HashMap, + io, + path::{Path, PathBuf}, +}; + use chrono::Utc; -use serde::Deserialize; -use serde::Serialize; -use std::collections::HashMap; -use std::io; -use std::path::{Path, PathBuf}; +use serde::{Deserialize, Serialize}; + +use super::{Manager, ManagerConfig}; /// Manages a collection of backup layers, allowing them to be utilized as a single object. pub struct MetaManager diff --git a/src/backup/manager/mod.rs b/src/backup/manager/mod.rs index 7cbd43c..ec91a3d 100644 --- a/src/backup/manager/mod.rs +++ b/src/backup/manager/mod.rs @@ -1,20 +1,20 @@ mod config; mod meta; -pub use config::ManagerConfig; -pub use meta::MetaManager; +use std::{ + fs::{File, OpenOptions}, + io, + path::{Path, PathBuf}, +}; + +use chrono::{SubsecRound, Utc}; +use flate2::{write::GzEncoder, Compression}; +use serde::{Deserialize, Serialize}; use super::{Backup, BackupType, Delta, State}; use crate::other; -use chrono::SubsecRound; -use chrono::Utc; -use flate2::write::GzEncoder; -use flate2::Compression; -use serde::Deserialize; -use serde::Serialize; -use std::fs::{File, OpenOptions}; -use std::io; -use std::path::{Path, PathBuf}; +pub use config::ManagerConfig; +pub use meta::MetaManager; /// Manages a single backup layer consisting of one or more chains of backups. pub struct Manager diff --git a/src/backup/mod.rs b/src/backup/mod.rs index 6bd798f..c833b55 100644 --- a/src/backup/mod.rs +++ b/src/backup/mod.rs @@ -4,23 +4,24 @@ pub mod manager; mod path; mod state; +use std::{ + collections::HashSet, + fmt, + fs::File, + io, + path::{Path, PathBuf}, +}; + +use chrono::Utc; +use flate2::{read::GzDecoder, write::GzEncoder, Compression}; +use serde::{Deserialize, Serialize}; + use delta::Delta; pub use manager::Manager; pub use manager::ManagerConfig; pub use manager::MetaManager; -pub use state::State; - -use chrono::Utc; -use flate2::read::GzDecoder; -use flate2::write::GzEncoder; -use flate2::Compression; use path::PathExt; -use serde::{Deserialize, Serialize}; -use std::collections::HashSet; -use std::fmt; -use std::fs::File; -use std::io; -use std::path::{Path, PathBuf}; +pub use state::State; const BYTE_SUFFIXES: [&str; 5] = ["B", "KiB", "MiB", "GiB", "TiB"]; diff --git a/src/backup/path.rs b/src/backup/path.rs index 77c6883..d8c2cec 100644 --- a/src/backup/path.rs +++ b/src/backup/path.rs @@ -1,9 +1,12 @@ +use std::{ + collections::HashSet, + ffi::OsString, + fs::{self, DirEntry}, + io, + path::{Path, PathBuf}, +}; + use chrono::{Local, Utc}; -use std::collections::HashSet; -use std::ffi::OsString; -use std::fs::DirEntry; -use std::path::{Path, PathBuf}; -use std::{fs, io}; pub struct ReadDirRecursive { ignored: HashSet, diff --git a/src/backup/state.rs b/src/backup/state.rs index de4b2c0..1f81abb 100644 --- a/src/backup/state.rs +++ b/src/backup/state.rs @@ -1,9 +1,13 @@ -use crate::backup::Delta; +use std::{ + borrow::Borrow, + collections::{HashMap, HashSet}, + ops::{Deref, DerefMut}, + path::{Path, PathBuf}, +}; + use serde::{Deserialize, Serialize}; -use std::borrow::Borrow; -use std::collections::{HashMap, HashSet}; -use std::ops::{Deref, DerefMut}; -use std::path::{Path, PathBuf}; + +use crate::backup::Delta; /// Struct that represents a current state for a backup. This struct acts as a smart pointer around /// a HashMap. diff --git a/src/cli/backup.rs b/src/cli/backup.rs index 85c0cee..548facc 100644 --- a/src/cli/backup.rs +++ b/src/cli/backup.rs @@ -1,10 +1,11 @@ -use crate::backup::Backup; -use crate::other; -use chrono::{TimeZone, Utc}; -use clap::{Args, Subcommand}; use std::io; use std::path::{Path, PathBuf}; +use chrono::{TimeZone, Utc}; +use clap::{Args, Subcommand}; + +use crate::{backup::Backup, other}; + #[derive(Subcommand)] pub enum BackupCommands { /// List all tracked backups diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 7a76ea1..4eaf6f8 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -2,28 +2,33 @@ mod backup; mod config; mod run; -pub use crate::backup::MetaManager; -pub use crate::server::Metadata; -pub use backup::{BackupArgs, BackupCommands}; -pub use run::RunCli; +use std::path::PathBuf; -use crate::backup::ManagerConfig; -use crate::server::ServerType; use clap::{Args, Parser, Subcommand}; -pub use config::Config; use figment::{ providers::{Env, Format, Serialized, Toml}, Figment, }; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; -#[derive(Subcommand)] -pub enum Commands { - /// Run the server - Run(RunCli), - /// Interact with the backup system without starting a server - Backup(BackupArgs), +use crate::{backup::ManagerConfig, server::ServerType}; +use backup::BackupArgs; +use config::Config; +use run::RunCli; + +#[derive(Parser, Serialize)] +#[command(author, version, about, long_about = None)] +pub struct Cli { + #[command(subcommand)] + #[serde(skip)] + pub command: Commands, + + /// Path to a TOML configuration file + #[arg(long = "config-file", global = true)] + pub config_file: Option, + + #[command(flatten)] + pub args: CliArgs, } #[derive(Args, Serialize, Deserialize, Clone)] @@ -60,19 +65,12 @@ pub struct CliArgs { pub server_version: Option, } -#[derive(Parser, Serialize)] -#[command(author, version, about, long_about = None)] -pub struct Cli { - #[command(subcommand)] - #[serde(skip)] - pub command: Commands, - - /// Path to a TOML configuration file - #[arg(long = "config-file", global = true)] - pub config_file: Option, - - #[command(flatten)] - pub args: CliArgs, +#[derive(Subcommand)] +pub enum Commands { + /// Run the server + Run(RunCli), + /// Interact with the backup system without starting a server + Backup(BackupArgs), } impl Cli { diff --git a/src/cli/run/mod.rs b/src/cli/run/mod.rs index fb48491..21c6a0a 100644 --- a/src/cli/run/mod.rs +++ b/src/cli/run/mod.rs @@ -1,15 +1,16 @@ mod config; -use crate::server; -use crate::signals; -use crate::stdin; -use clap::Args; -use config::Config; -use std::path::PathBuf; -use std::sync::{Arc, Mutex}; +use std::{ + path::PathBuf, + sync::{Arc, Mutex}, +}; +use clap::Args; use serde::{Deserialize, Serialize}; +use crate::{server, signals, stdin}; +use config::Config; + #[derive(Args)] pub struct RunCli { #[command(flatten)] diff --git a/src/signals.rs b/src/signals.rs index 61c38f9..5462a75 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -1,10 +1,13 @@ -use std::io; -use std::sync::atomic::AtomicBool; -use std::sync::{Arc, Mutex}; +use std::{ + io, + sync::{atomic::AtomicBool, Arc, Mutex}, +}; -use signal_hook::consts::TERM_SIGNALS; -use signal_hook::flag; -use signal_hook::iterator::{Signals, SignalsInfo}; +use signal_hook::{ + consts::TERM_SIGNALS, + flag, + iterator::{Signals, SignalsInfo}, +}; use crate::server; diff --git a/src/stdin.rs b/src/stdin.rs index f9a22e8..4a7f761 100644 --- a/src/stdin.rs +++ b/src/stdin.rs @@ -1,5 +1,7 @@ -use std::io; -use std::sync::{Arc, Mutex}; +use std::{ + io, + sync::{Arc, Mutex}, +}; use crate::server;