]> git.puffer.fish Git - matthieu/nova.git/commitdiff
Fix some warnings
authorn1c00o <git.n1c00o@gmail.com>
Sat, 16 Oct 2021 20:18:25 +0000 (22:18 +0200)
committern1c00o <git.n1c00o@gmail.com>
Sat, 16 Oct 2021 20:18:25 +0000 (22:18 +0200)
common/rust/src/config.rs
common/rust/src/nats.rs
common/rust/src/payloads.rs

index c158a2143f301bfc3c4a81e80f9d2dab323e9807..bd123502b832138b3ee2651ab906b26be5f02002 100644 (file)
@@ -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<T> {
     pub nats: crate::nats::NatsConfiguration,
 }
 
-impl<T> Settings<T> where T: Deserialize<'static> + std::default::Default + Clone {
+impl<T> Settings<T>
+where
+    T: Deserialize<'static> + std::default::Default + Clone,
+{
     pub fn new(service_name: &str) -> Result<Settings<T>, ConfigError> {
         let mut default = Config::default();
         // this file my be shared with all the components
@@ -30,7 +32,7 @@ impl<T> Settings<T> where T: Deserialize<'static> + std::default::Default + Clon
         let mut config: Settings<T> = default.clone().try_into().unwrap();
 
         //  try to load the config
-        config.config = default.get::<T>(&service_name).unwrap();
+        config.config = default.get::<T>(service_name).unwrap();
         pretty_env_logger::init();
 
         // start the monitoring system if needed
index 59b480c7239bc881b7910394646ce0e2e159771a..1a4d349c74fd2e5aa0785665f6c37bcea33447e2 100644 (file)
@@ -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<Connection> 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<Connection> 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();
index 38d752989d6fe56adbcc6c2ea1ea7b35f01edbb6..4f70b451e7c7a97491019e7e5eff5bb799b65b5c 100644 (file)
@@ -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<Interaction>,
     },
     MessageCreate {
         message: Message,