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"))]
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
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
-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 {
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);
}
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();
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,