From 03908129599260587fe7b9fd8254d28ad50b8714 Mon Sep 17 00:00:00 2001 From: n1c00o Date: Sat, 16 Oct 2021 22:18:25 +0200 Subject: [PATCH] Fix some warnings --- common/rust/src/config.rs | 10 ++++++---- common/rust/src/nats.rs | 12 ++++++------ common/rust/src/payloads.rs | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/common/rust/src/config.rs b/common/rust/src/config.rs index c158a21..bd12350 100644 --- a/common/rust/src/config.rs +++ b/common/rust/src/config.rs @@ -2,8 +2,7 @@ use std::env; use config::{Config, ConfigError, Environment, File}; use log::info; -use serde::{Deserialize}; - +use serde::Deserialize; #[derive(Debug, Deserialize, Clone)] #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] @@ -14,7 +13,10 @@ pub struct Settings { pub nats: crate::nats::NatsConfiguration, } -impl Settings where T: Deserialize<'static> + std::default::Default + Clone { +impl Settings +where + T: Deserialize<'static> + std::default::Default + Clone, +{ pub fn new(service_name: &str) -> Result, ConfigError> { let mut default = Config::default(); // this file my be shared with all the components @@ -30,7 +32,7 @@ impl Settings where T: Deserialize<'static> + std::default::Default + Clon let mut config: Settings = default.clone().try_into().unwrap(); // try to load the config - config.config = default.get::(&service_name).unwrap(); + config.config = default.get::(service_name).unwrap(); pretty_env_logger::init(); // start the monitoring system if needed diff --git a/common/rust/src/nats.rs b/common/rust/src/nats.rs index 59b480c..1a4d349 100644 --- a/common/rust/src/nats.rs +++ b/common/rust/src/nats.rs @@ -1,10 +1,10 @@ -use nats::{Options, Connection}; +use nats::{Connection, Options}; use serde::Deserialize; #[derive(Clone, Debug, Deserialize)] struct NatsConfigurationClientCert { cert: String, - key: String + key: String, } #[derive(Clone, Debug, Deserialize)] struct NatsConfigurationTls { @@ -24,11 +24,12 @@ pub struct NatsConfiguration { host: String, } -/// +// todo: Prefer From since it automatically gives a free Into implementation +/// impl Into for NatsConfiguration { fn into(self) -> Connection { let mut options = Options::new(); - + if let Some(client_cert) = self.client_cert { options = options.client_cert(client_cert.cert, client_cert.key); } @@ -47,8 +48,7 @@ impl Into for NatsConfiguration { options = options.no_echo(); options = options.reconnect_buffer_size(self.reconnect_buffer_size.unwrap_or(64 * 1024)); options = options.tls_required(self.tls_required.unwrap_or(false)); - options = options.with_name(&self.client_name.unwrap_or("Nova".to_string())); - + options = options.with_name(&self.client_name.unwrap_or_else(|| "Nova".to_string())); if let Some(tls) = self.tls { let mut config = nats::rustls::ClientConfig::new(); diff --git a/common/rust/src/payloads.rs b/common/rust/src/payloads.rs index 38d7529..4f70b45 100644 --- a/common/rust/src/payloads.rs +++ b/common/rust/src/payloads.rs @@ -186,7 +186,8 @@ pub enum CacheData { code: String, }, InteractionCreate { - interaction: Interaction, + // boxed to avoid a large difference size between variants (https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant) + interaction: Box, }, MessageCreate { message: Message, -- 2.39.5