summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/rust/src/config.rs10
-rw-r--r--common/rust/src/nats.rs12
-rw-r--r--common/rust/src/payloads.rs3
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<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
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<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();
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<Interaction>,
},
MessageCreate {
message: Message,