Skip to content

Commit

Permalink
refac for clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
splurf committed Feb 20, 2024
1 parent 06377bf commit e8a313a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use {
std::{net::IpAddr, thread::sleep, time::Duration},
};

type BaseClientBuilder = Box<dyn Fn(Method, &Client) -> RequestBuilder>;

#[derive(Parser)]
#[command(author, version, about)]
pub struct Config {
Expand Down Expand Up @@ -41,7 +43,7 @@ impl Default for Config {
pub struct BaseClient {
client: Client,
body: Body,
builder_fn: Box<dyn Fn(Method, &Client) -> RequestBuilder>,
builder_fn: BaseClientBuilder,
delay: Duration,
}

Expand Down Expand Up @@ -105,7 +107,7 @@ impl BaseClient {
Self::PUBLIC_IP_API
.into_iter()
.find_map(|api| api.try_get(&self.client).ok())
.ok_or(Error::API)
.ok_or(Error::Api)
}

pub fn delay(&self) {
Expand Down
4 changes: 2 additions & 2 deletions src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
pub enum Error {
Reqwest(reqwest::Error),
Cloudflare,
API,
Api,
Invalid,
IO(std::io::Error),
ParseInt(std::num::ParseIntError),
Expand Down Expand Up @@ -38,7 +38,7 @@ impl std::fmt::Display for Error {
f.write_str(&match self {
Self::Reqwest(e) => e.to_string(),
Self::Cloudflare => "Failed to properly retrieve dns record".to_string(),
Self::API => "All public ip API failed".to_string(),
Self::Api => "All public ip API failed".to_string(),
Self::Invalid => "Invalid parsing for DNS record name".to_string(),
Self::IO(e) => e.to_string(),
Self::ParseInt(e) => e.to_string(),
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ fn main() -> Result<()> {
}
Err(e) => eprintln!("{}", e),
}
dbg("Delaying", || Ok(client.delay()))?;
dbg("Delaying", || {
client.delay();
Ok(())
})?;
}
}

0 comments on commit e8a313a

Please sign in to comment.