Skip to content
Snippets Groups Projects
Commit 6f4fbe3b authored by Éloïs's avatar Éloïs
Browse files

[ref] module: impl Merge for DursModule::ModuleUserConf

parent eb529db2
No related branches found
No related tags found
1 merge request!154[ref] module: impl Merge for DursModule::ModuleUserConf
......@@ -451,6 +451,7 @@ version = "0.1.0-a0.1"
dependencies = [
"dubp-documents 0.12.0",
"dup-crypto 0.6.0",
"durs-common-tools 0.1.0",
"durs-network-documents 0.3.1",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.86 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -12,6 +12,7 @@ path = "src/lib.rs"
[dependencies]
dup-crypto = { path = "../../tools/crypto" }
dubp-documents = { path = "../../tools/documents" }
durs-common-tools = { path = "../../tools/common-tools" }
durs-network-documents = { path = "../../tools/network-documents" }
failure = "0.1.5"
serde = "1.0.*"
......
......@@ -33,6 +33,7 @@ extern crate serde_derive;
use dubp_documents::CurrencyName;
use dup_crypto::keys::{KeyPair, KeyPairEnum};
use durs_common_tools::traits::merge::Merge;
use durs_network_documents::network_endpoint::{ApiPart, EndpointEnum};
use failure::Fail;
use serde::de::DeserializeOwned;
......@@ -395,7 +396,14 @@ impl From<ModuleConfError> for PlugModuleError {
/// All Duniter-rs modules must implement this trait.
pub trait DursModule<DC: DursConfTrait, M: ModuleMessage> {
///Module user configuration (configuration provided by the user)
type ModuleUserConf: Clone + Debug + Default + DeserializeOwned + Send + Serialize + Sync;
type ModuleUserConf: Clone
+ Debug
+ Default
+ DeserializeOwned
+ Merge
+ Send
+ Serialize
+ Sync;
/// Module real configuration (configuration calculated from the configuration provided by the user and the global configuration)
type ModuleConf: 'static + Clone + Debug + Default + Send + Sync;
/// Module subcommand options
......
......@@ -35,6 +35,7 @@ extern crate serde_derive;
extern crate structopt;
use durs_common_tools::fatal_error;
use durs_common_tools::traits::merge::Merge;
use durs_conf::DuRsConf;
use durs_message::events::*;
use durs_message::*;
......@@ -68,6 +69,14 @@ pub struct SkeletonUserConf {
test_fake_conf_field: Option<String>,
}
impl Merge for SkeletonUserConf {
fn merge(self, other: Self) -> Self {
SkeletonUserConf {
test_fake_conf_field: self.test_fake_conf_field.or(other.test_fake_conf_field),
}
}
}
#[derive(Debug, Copy, Clone)]
/// Message from others thread of skeleton module
pub enum SkeletonThreadMsg {}
......
......@@ -36,6 +36,7 @@ extern crate serde_derive;
extern crate structopt;
use durs_common_tools::fatal_error;
use durs_common_tools::traits::merge::Merge;
use durs_conf::DuRsConf;
use durs_message::events::*;
use durs_message::*;
......@@ -64,6 +65,12 @@ impl Default for TuiConf {
}
}
impl Merge for TuiConf {
fn merge(self, _: Self) -> Self {
self
}
}
#[derive(Debug, Clone)]
/// Format of messages received by the tui module
pub enum TuiMess {
......
......@@ -61,6 +61,7 @@ use crate::ws_connections::*;
use dubp_documents::{Blockstamp, CurrencyName};
use dup_crypto::keys::*;
use durs_common_tools::fatal_error;
use durs_common_tools::traits::merge::Merge;
use durs_conf::DuRsConf;
use durs_message::events::*;
use durs_message::requests::*;
......@@ -111,6 +112,16 @@ pub struct WS2PUserConf {
pub sync_endpoints: Option<Vec<EndpointV1>>,
}
impl Merge for WS2PUserConf {
fn merge(self, other: Self) -> Self {
WS2PUserConf {
outcoming_quota: self.outcoming_quota.or(other.outcoming_quota),
prefered_pubkeys: self.prefered_pubkeys.or(other.prefered_pubkeys),
sync_endpoints: self.sync_endpoints.or(other.sync_endpoints),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
/// WS2P Configuration
pub struct WS2PConf {
......
......@@ -41,6 +41,7 @@ pub mod services;
use crate::errors::WS2PError;
use durs_common_tools::fatal_error;
use durs_common_tools::traits::merge::Merge;
use durs_conf::DuRsConf;
use durs_message::DursMsg;
use durs_module::*;
......@@ -68,6 +69,15 @@ pub struct WS2PUserConf {
pub sync_endpoints: Option<Vec<EndpointEnum>>,
}
impl Merge for WS2PUserConf {
fn merge(self, other: Self) -> Self {
WS2PUserConf {
outcoming_quota: self.outcoming_quota.or(other.outcoming_quota),
sync_endpoints: self.sync_endpoints.or(other.sync_endpoints),
}
}
}
impl Default for WS2PConf {
fn default() -> Self {
WS2PConf {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment