Skip to content

Commit

Permalink
fix: build and clippy lints
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Sep 11, 2023
1 parent 36297f8 commit e53f836
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 15 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ serde = "1"
serde_derive = "1.0.188"
serde_json = "1"
serde_with = "3"
tokio = "1"
tokio = { version = "1", features = ["full"] }
toml = "0.7.8"
tungstenite = "0.20"
url = "2.4"
6 changes: 4 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use url::Url;
mod message;
use message::{BackupMessage, BackupResultMessage, HandshakeMessage};

#[derive(Parser)]
#[derive(clap_derive::Parser)]
#[command(author, version, about, long_about = None)]
struct Opts {
#[clap(long)]
Expand Down Expand Up @@ -64,7 +64,9 @@ fn connect_client(server: Url, name: String) -> Result<()> {
let snap_msg = match do_backup(backup_msg) {
Ok(snap) => {
println!("{snap:?}");
BackupResultMessage::Ok { snapshot: snap }
BackupResultMessage::Ok {
snapshot: Box::new(snap),
}
}
Err(err) => BackupResultMessage::Error {
message: err.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ pub struct BackupMessage {
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "result")]
pub enum BackupResultMessage {
Ok { snapshot: SnapshotFile },
Ok { snapshot: Box<SnapshotFile> },
Error { message: String },
}
26 changes: 15 additions & 11 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ impl Client {
fn next_invocation(&self) -> Option<Time> {
match self.state {
ClientState::Idle | ClientState::NotConnected => {
self.sources.get(0).map(|s| s.next_invocation).flatten()
self.sources.get(0).and_then(|s| s.next_invocation)
}
ClientState::Processing(_) => None,
}
}

fn to_processing(&mut self, time: Time) -> (String, ClientState) {
fn to_processing_mut(&mut self, time: Time) -> (String, ClientState) {
println!("backing up {}", self.sources[0].source);
let state = std::mem::replace(&mut self.state, ClientState::Processing(time));
(self.sources[0].source.clone(), state)
Expand All @@ -70,7 +70,7 @@ impl Client {
self.sort_sources();
}

fn to_idle(&mut self, time: Time, status: SourceBackupStatus) {
fn to_idle_mut(&mut self, time: Time, status: SourceBackupStatus) {
if let ClientState::Processing(start_time) = self.state {
let source = &mut self.sources[0];
source.last_success = source.next_invocation;
Expand Down Expand Up @@ -110,6 +110,7 @@ pub struct Source {
history: Vec<SourceBackup>,
}

#[allow(dead_code)]
pub struct SourceBackup {
scheduled: Time,
real: Time,
Expand Down Expand Up @@ -143,12 +144,12 @@ impl Source {
struct NextAction(Option<(String, Time)>);

impl NextAction {
fn min_with(&mut self, name: &String, date: Option<Time>) {
fn min_with(&mut self, name: &str, date: Option<Time>) {
if let Some(date) = date {
match self.0 {
Some((_, cur_date)) if date >= cur_date => {}
_ => {
self.0 = Some((name.clone(), date));
self.0 = Some((name.clone().to_owned(), date));
}
}
}
Expand Down Expand Up @@ -177,7 +178,7 @@ impl Clients {
.clients
.iter()
.fold(NextAction(None), |mut acc, (name, client)| {
acc.min_with(&name, client.next_invocation());
acc.min_with(name, client.next_invocation());
acc
});
self.next_action = next_action;
Expand Down Expand Up @@ -218,7 +219,7 @@ impl Clients {
None
}
ClientState::Idle => {
let (source, _) = client.to_processing(time);
let (source, _) = client.to_processing_mut(time);
Some((next_client.clone(), source))
}
}
Expand All @@ -229,7 +230,10 @@ impl Clients {
}

pub fn finish_process(&mut self, client: String, time: Time, status: SourceBackupStatus) {
self.clients.get_mut(&client).unwrap().to_idle(time, status);
self.clients
.get_mut(&client)
.unwrap()
.to_idle_mut(time, status);
self.compute_next_action();
}

Expand All @@ -245,9 +249,9 @@ impl Clients {
}

pub fn disconnect_client(&mut self, client: String) {
self.clients
.get_mut(&client)
.map(|client| client.disconnect());
if let Some(client) = self.clients.get_mut(&client) {
client.disconnect()
}
self.compute_next_action();
}
}

0 comments on commit e53f836

Please sign in to comment.