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

[ref] module: simplify even more DuniterModule Trait

parent e86ef6fd
No related branches found
No related tags found
No related merge requests found
...@@ -41,22 +41,24 @@ pub type Endpoint = String; ...@@ -41,22 +41,24 @@ pub type Endpoint = String;
pub trait DuniterModule: 'static + Sized { pub trait DuniterModule: 'static + Sized {
const INDEX_BLOCKS: bool = false; const INDEX_BLOCKS: bool = false;
/// This function is called only if Self::INDEX_BLOCKS is true,
/// in this case it must be reimplemented because the default implementation panics.
fn apply_block( fn apply_block(
_block: &DubpBlockV10, _block: &DubpBlockV10,
_conf: &duniter_conf::DuniterConf, _conf: &duniter_conf::DuniterConf,
_shared_dbs: &SharedDbs<FileBackend>,
_profile_path_opt: Option<&Path>, _profile_path_opt: Option<&Path>,
) -> KvResult<()> { ) -> KvResult<()> {
Ok(()) unreachable!()
} }
/// This function is called only if Self::INDEX_BLOCKS is true,
/// in this case it must be reimplemented because the default implementation panics.
fn revert_block( fn revert_block(
_block: &DubpBlockV10, _block: &DubpBlockV10,
_conf: &duniter_conf::DuniterConf, _conf: &duniter_conf::DuniterConf,
_shared_dbs: &SharedDbs<FileBackend>,
_profile_path_opt: Option<&Path>, _profile_path_opt: Option<&Path>,
) -> KvResult<()> { ) -> KvResult<()> {
Ok(()) unreachable!()
} }
fn init( fn init(
...@@ -118,10 +120,9 @@ macro_rules! plug_duniter_modules { ...@@ -118,10 +120,9 @@ macro_rules! plug_duniter_modules {
let conf_arc_clone = Arc::clone(&conf); let conf_arc_clone = Arc::clone(&conf);
let profile_path_opt_clone = profile_path_opt.clone(); let profile_path_opt_clone = profile_path_opt.clone();
Some(dbs_pool Some(dbs_pool
.launch(move |shared_dbs| <$M>::apply_block( .launch(move |_| <$M>::apply_block(
&block_arc_clone, &block_arc_clone,
&conf_arc_clone, &conf_arc_clone,
&shared_dbs,
profile_path_opt_clone.as_deref() profile_path_opt_clone.as_deref()
)) ))
.expect("thread pool disconnected")) .expect("thread pool disconnected"))
...@@ -149,10 +150,10 @@ macro_rules! plug_duniter_modules { ...@@ -149,10 +150,10 @@ macro_rules! plug_duniter_modules {
let conf_arc_clone = Arc::clone(&conf); let conf_arc_clone = Arc::clone(&conf);
let profile_path_opt_clone = profile_path_opt.clone(); let profile_path_opt_clone = profile_path_opt.clone();
Some(dbs_pool Some(dbs_pool
.launch(move |shared_dbs| { .launch(move |_| {
use std::ops::Deref as _; use std::ops::Deref as _;
for block in blocks_arc_clone.deref() { for block in blocks_arc_clone.deref() {
<$M>::apply_block(&block, &conf_arc_clone, &shared_dbs, profile_path_opt_clone.as_deref())?; <$M>::apply_block(&block, &conf_arc_clone, profile_path_opt_clone.as_deref())?;
} }
Ok::<_, KvError>(()) Ok::<_, KvError>(())
}) })
...@@ -181,10 +182,9 @@ macro_rules! plug_duniter_modules { ...@@ -181,10 +182,9 @@ macro_rules! plug_duniter_modules {
let conf_arc_clone = Arc::clone(&conf); let conf_arc_clone = Arc::clone(&conf);
let profile_path_opt_clone = profile_path_opt.clone(); let profile_path_opt_clone = profile_path_opt.clone();
Some(dbs_pool Some(dbs_pool
.launch(move |shared_dbs| <$M>::revert_block( .launch(move |_| <$M>::revert_block(
&block_arc_clone, &block_arc_clone,
&conf_arc_clone, &conf_arc_clone,
&shared_dbs,
profile_path_opt_clone.as_deref() profile_path_opt_clone.as_deref()
)) ))
.expect("thread pool disconnected")) .expect("thread pool disconnected"))
......
...@@ -63,7 +63,6 @@ impl duniter_module::DuniterModule for GvaModule { ...@@ -63,7 +63,6 @@ impl duniter_module::DuniterModule for GvaModule {
fn apply_block( fn apply_block(
block: &DubpBlockV10, block: &DubpBlockV10,
_conf: &duniter_conf::DuniterConf, _conf: &duniter_conf::DuniterConf,
_shared_dbs: &SharedDbs<FileBackend>,
profile_path_opt: Option<&Path>, profile_path_opt: Option<&Path>,
) -> KvResult<()> { ) -> KvResult<()> {
let gva_db = get_gva_db_rw(profile_path_opt); let gva_db = get_gva_db_rw(profile_path_opt);
...@@ -72,7 +71,6 @@ impl duniter_module::DuniterModule for GvaModule { ...@@ -72,7 +71,6 @@ impl duniter_module::DuniterModule for GvaModule {
fn revert_block( fn revert_block(
block: &DubpBlockV10, block: &DubpBlockV10,
_conf: &duniter_conf::DuniterConf, _conf: &duniter_conf::DuniterConf,
_shared_dbs: &SharedDbs<FileBackend>,
profile_path_opt: Option<&Path>, profile_path_opt: Option<&Path>,
) -> KvResult<()> { ) -> KvResult<()> {
let gva_db = get_gva_db_rw(profile_path_opt); let gva_db = get_gva_db_rw(profile_path_opt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment