Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vorner committed Jan 23, 2023
1 parent d5bff41 commit 4fcbfa0
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 97 deletions.
4 changes: 2 additions & 2 deletions examples/hws-complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn hello(global_cfg: &Cfg, cfg: &Arc<Server>, req: Request<Body>) -> Response<Bo
let mut msg = format!("{}\n", global_cfg.ui.msg);
// Get some listener-local configuration.
if let Some(ref signature) = extract_signature(cfg) {
msg.push_str(&format!("Brought to you by {}\n", signature));
msg.push_str(&format!("Brought to you by {signature}\n"));
}
Response::new(Body::from(msg))
}
Expand Down Expand Up @@ -296,7 +296,7 @@ fn main() {
//
// Note that if a file is added or removed at runtime and the application receives SIGHUP,
// the change is reflected.
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
// Put help options early. They may terminate the program and we may want to do it before
// daemonization or other side effects.
.with(CfgOpts::extension(Opts::cfg_opts))
Expand Down
2 changes: 1 addition & 1 deletion examples/hws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn main() -> Result<(), AnyError> {
.config_defaults(DEFAULT_CONFIG)
// If the user passes a directory path instead of file path, take files with these
// extensions and load config from there.
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
// Config can be read from environment too
.config_env("HWS")
// Perform some more validation of the results.
Expand Down
2 changes: 1 addition & 1 deletion spirit-cfg-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl DumpFormat {
serde_yaml::to_string(cfg).expect("Dirty stuff in config, can't dump")
}
};
println!("{}", dump);
println!("{dump}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion spirit-daemonize/examples/go_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sleep_ms = 100
fn main() {
Spirit::<Opts, Cfg>::new()
.config_defaults(DEFAULT_CONFIG)
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
.with(unsafe {
spirit_daemonize::extension(|c: &Cfg, o: &Opts| (c.daemon.clone(), o.daemon.clone()))
})
Expand Down
14 changes: 5 additions & 9 deletions spirit-daemonize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Daemonize {
.context("Failed to open /dev/null")?;
for fd in &[0, 1, 2] {
unistd::dup2(devnull.as_raw_fd(), *fd)
.with_context(|_| format!("Failed to redirect FD {}", fd))?;
.with_context(|_| format!("Failed to redirect FD {fd}"))?;
}
trace!("Doing double fork");
if let ForkResult::Parent { .. } = unistd::fork().context("Failed to fork")? {
Expand Down Expand Up @@ -164,6 +164,7 @@ impl Daemonize {
#[cfg_attr(feature = "cfg-help", derive(StructDoc))]
#[serde(untagged)]
#[non_exhaustive]
#[derive(Default)]
pub enum SecId {
/// Look up based on the name.
Name(String),
Expand All @@ -174,6 +175,7 @@ pub enum SecId {
/// This is not read from configuration, but it is the default value available if nothing is
/// listed in configuration.
#[serde(skip)]
#[default]
Nothing,
}

Expand All @@ -183,12 +185,6 @@ impl SecId {
}
}

impl Default for SecId {
fn default() -> Self {
SecId::Nothing
}
}

/// A configuration fragment for configuration of daemonization.
///
/// This describes how to go into background with some details.
Expand Down Expand Up @@ -276,7 +272,7 @@ impl Daemon {
unistd::setgid(Gid::from_raw(id)).context("Failed to change the group")?
}
SecId::Name(ref name) => privdrop::PrivDrop::default()
.group(&name)
.group(name)
.apply()
.context("Failed to change the group")?,
SecId::Nothing => (),
Expand All @@ -286,7 +282,7 @@ impl Daemon {
unistd::setuid(Uid::from_raw(id)).context("Failed to change the user")?
}
SecId::Name(ref name) => privdrop::PrivDrop::default()
.user(&name)
.user(name)
.apply()
.context("Failed to change the user")?,
SecId::Nothing => (),
Expand Down
6 changes: 3 additions & 3 deletions spirit-dipstick/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ impl Backend {
.map_err(Box::from),
Backend::Graphite { host, port } => Graphite::send_to((host as &str, *port))
.map(|g| out.add_target(g))
.with_context(|_| format!("Error sending to graphite {}:{}", host, port))
.with_context(|_| format!("Error sending to graphite {host}:{port}"))
.map_err(Box::from),
Backend::Prometheus { url } => Prometheus::push_to(url as &str)
.map(|p| out.add_target(p))
.with_context(|_| format!("Error sending to prometheus {}", url))
.with_context(|_| format!("Error sending to prometheus {url}"))
.map_err(Box::from),
Backend::Statsd { host, port } => Statsd::send_to((host as &str, *port))
.map(|s| out.add_target(s))
.with_context(|_| format!("Error sending to statsd {}:{}", host, port))
.with_context(|_| format!("Error sending to statsd {host}:{port}"))
.map_err(Box::from),
}
}
Expand Down
4 changes: 2 additions & 2 deletions spirit-hyper/examples/hws-hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn hello(
let mut msg = format!("{}\n", spirit.config().ui.msg);
// Get some listener-local configuration.
if let Some(ref signature) = cfg.transport.listen.extra_cfg.signature {
msg.push_str(&format!("Brought to you by {}\n", signature));
msg.push_str(&format!("Brought to you by {signature}\n"));
}
Ok(Response::new(Body::from(msg)))
}
Expand All @@ -79,7 +79,7 @@ fn main() {

Spirit::<Empty, _>::new()
.config_defaults(DEFAULT_CONFIG)
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
// Explicitly enabling tokio integration, implicitly it would happen inside run and that's
// too late.
.with_singleton(Tokio::SingleThreaded) // Explicitly enabling tokio
Expand Down
12 changes: 3 additions & 9 deletions spirit-hyper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ fn is_default_timeout(t: &Duration) -> bool {
#[cfg_attr(feature = "cfg-help", derive(StructDoc))]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
#[derive(Default)]
pub enum HttpMode {
/// Enable both HTTP1 and HTTP2 protocols.
#[default]
Both,

/// Disable the HTTP2 protocol.
Expand All @@ -122,12 +124,6 @@ pub enum HttpMode {
Http2Only,
}

impl Default for HttpMode {
fn default() -> Self {
HttpMode::Both
}
}

/// Configuration of Hyper HTTP servers.
///
/// This are the things that are extra over the transport. It doesn't contain any kind of ports or
Expand Down Expand Up @@ -396,9 +392,7 @@ where
if let Err(e) = server.await {
log_error!(
Error,
e.into()
.context(format!("HTTP server error {}", name))
.into()
e.into().context(format!("HTTP server error {name}")).into()
);
}
trace!("Server {} terminated", name);
Expand Down
2 changes: 1 addition & 1 deletion spirit-log/examples/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod everything {
pub(crate) fn run() {
Spirit::<Opts, Cfg>::new()
.config_defaults(DEFAULT_CONFIG)
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
.with(
Pipeline::new("logging")
.extract(|opts: &Opts, cfg: &Cfg| LogBoth {
Expand Down
2 changes: 1 addition & 1 deletion spirit-log/examples/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sleep_ms = 100
fn main() {
Spirit::<Opts, Cfg>::new()
.config_defaults(DEFAULT_CONFIG)
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
.with(
Pipeline::new("logging").extract(|opts: &Opts, cfg: &Cfg| LogBoth {
cfg: cfg.logging(),
Expand Down
4 changes: 2 additions & 2 deletions spirit-log/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Instruction {
LOG_THREAD_NAME.with(|n| n.replace(Some(thread)));
dst.log(
&Record::builder()
.args(format_args!("{}", msg))
.args(format_args!("{msg}"))
.level(level)
.target(&target)
.file(file.as_ref().map(|f| f as &str))
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Recv {
reset_thread_name();
self.shared.logger.log(
&Record::builder()
.args(format_args!("Lost {} messages", lost_msgs))
.args(format_args!("Lost {lost_msgs} messages"))
.level(Level::Warn)
.target(module_path!())
.line(Some(line!()))
Expand Down
24 changes: 8 additions & 16 deletions spirit-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ impl std::error::Error for SyslogError {}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "cfg-help", derive(StructDoc))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[derive(Default)]
enum Clock {
#[default]
Local,
Utc,
}
Expand All @@ -378,12 +380,6 @@ impl Clock {
}
}

impl Default for Clock {
fn default() -> Self {
Clock::Local
}
}

fn default_time_format() -> String {
"%+".to_owned()
}
Expand All @@ -395,10 +391,12 @@ fn cmdline_time_format() -> String {
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "cfg-help", derive(StructDoc))]
#[serde(rename_all = "kebab-case")]
#[derive(Default)]
enum Format {
/// Only the message, without any other fields.
MessageOnly,
/// The time, log level, log target and message in columns.
#[default]
Short,
/// The time, log level, thread name, log target and message in columns.
Extended,
Expand Down Expand Up @@ -439,12 +437,6 @@ enum Format {
// TODO: Custom
}

impl Default for Format {
fn default() -> Self {
Format::Short
}
}

#[cfg(not(feature = "background"))]
fn get_thread_name(thread: &thread::Thread) -> &str {
thread.name().unwrap_or(UNKNOWN_THREAD)
Expand Down Expand Up @@ -514,7 +506,7 @@ impl Logger {
_ => {
logger = logger.format(move |out, message, record| {
match format {
Format::MessageOnly => out.finish(format_args!("{}", message)),
Format::MessageOnly => out.finish(format_args!("{message}")),
Format::Short => out.finish(format_args!(
"{} {:5} {:30} {}",
clock.now(&time_format),
Expand Down Expand Up @@ -582,7 +574,7 @@ impl Logger {
// TODO: Maybe use some shortstring or so here to avoid allocation?
let msg = serde_json::to_string(msg)
.expect("Failed to serialize JSON log");
out.finish(format_args!("{}", msg));
out.finish(format_args!("{msg}"));
};
log(&Msg {
timestamp: format_args!("{}", clock.now(&time_format)),
Expand Down Expand Up @@ -621,7 +613,7 @@ impl Logger {
// TODO: Maybe use some shortstring or so here to avoid allocation?
let msg = serde_json::to_string(msg)
.expect("Failed to serialize JSON log");
out.finish(format_args!("{}", msg));
out.finish(format_args!("{msg}"));
};
log(&Msg {
timestamp: format_args!("{}", clock.now(&time_format)),
Expand Down Expand Up @@ -716,7 +708,7 @@ where
/// - `message-only`: The line contains only the message itself.
/// - `short`: This is the default. `<timestamp> <level> <target> <message>`. Padded to form
/// columns.
/// - `extended`: <timestamp> <level> <thread-name> <target> <message>`. Padded to form columns.
/// - `extended`: `<timestamp> <level> <thread-name> <target> <message>`. Padded to form columns.
/// - `full`: `<timestamp> <level> <thread-name> <file>:<line> <target> <message>`. Padded to
/// form columns.
/// - `machine`: Like `full`, but columns are not padded by spaces, they are separated by a
Expand Down
2 changes: 1 addition & 1 deletion spirit-reqwest/examples/make_request_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn make_request(client: &Client) -> Result<(), AnyError> {
.error_for_status()?
.text()
.await?;
println!("{}", page);
println!("{page}");
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions spirit-reqwest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ impl ReqwestClient {
let mut headers = HeaderMap::new();
for (key, val) in &self.default_headers {
let name = HeaderName::from_bytes(key.as_bytes())
.with_context(|_| format!("{} is not a valiad header name", key))?;
.with_context(|_| format!("{key} is not a valiad header name"))?;
let header = HeaderValue::from_bytes(val.as_bytes())
.with_context(|_| format!("{} is not a valid header", val))?;
.with_context(|_| format!("{val} is not a valid header"))?;
headers.insert(name, header);
}
let redirects = match self.redirects {
Expand Down Expand Up @@ -480,7 +480,7 @@ impl ReqwestClient {
for cert_path in &self.tls_extra_root_certs {
trace!("Adding root certificate {:?}", cert_path);
let cert = load_cert(cert_path)
.with_context(|_| format!("Failed to load certificate {:?}", cert_path))?;
.with_context(|_| format!("Failed to load certificate {cert_path:?}"))?;
builder = builder.add_root_certificate(cert);
}
#[cfg(feature = "native-tls")]
Expand All @@ -504,13 +504,13 @@ impl ReqwestClient {
if let Some(proxy) = &self.http_proxy {
let proxy_url = proxy.clone();
let proxy = Proxy::http(proxy_url)
.with_context(|_| format!("Failed to configure http proxy to {:?}", proxy))?;
.with_context(|_| format!("Failed to configure http proxy to {proxy:?}"))?;
builder = builder.proxy(proxy);
}
if let Some(proxy) = &self.https_proxy {
let proxy_url = proxy.clone();
let proxy = Proxy::https(proxy_url)
.with_context(|_| format!("Failed to configure https proxy to {:?}", proxy))?;
.with_context(|_| format!("Failed to configure https proxy to {proxy:?}"))?;
builder = builder.proxy(proxy);
}
}
Expand Down
4 changes: 2 additions & 2 deletions spirit-tokio/examples/hws-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ pub fn main() {
}
};
Spirit::<Empty, Config>::new()
.on_config(move |_, cfg: &Arc<Config>| cfg_store.store(Arc::clone(&cfg)))
.on_config(move |_, cfg: &Arc<Config>| cfg_store.store(Arc::clone(cfg)))
.config_defaults(DEFAULT_CONFIG)
.config_exts(&["toml", "ini", "json"])
.config_exts(["toml", "ini", "json"])
.with_singleton(Tokio::from_cfg(Config::threadpool))
.with(
Pipeline::new("listen")
Expand Down
Loading

0 comments on commit 4fcbfa0

Please sign in to comment.