From b776087b2609ba76580a81ac3e70b8af5bb23b65 Mon Sep 17 00:00:00 2001 From: Vladimir Komendantskiy Date: Wed, 11 Apr 2018 15:44:59 +0100 Subject: [PATCH] removed redundant type constraint --- examples/consensus-node.rs | 2 +- src/broadcast/mod.rs | 19 ++++++++----------- src/node.rs | 8 ++++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/examples/consensus-node.rs b/examples/consensus-node.rs index e7884f4..abe4c44 100644 --- a/examples/consensus-node.rs +++ b/examples/consensus-node.rs @@ -1,6 +1,6 @@ //! Example of a consensus node that uses the `hbbft::node::Node` struct for //! running the distributed consensus state machine. -#[macro_use] +//#[macro_use] extern crate log; extern crate simple_logger; extern crate docopt; diff --git a/src/broadcast/mod.rs b/src/broadcast/mod.rs index 67784e4..3e8ced5 100644 --- a/src/broadcast/mod.rs +++ b/src/broadcast/mod.rs @@ -40,7 +40,6 @@ pub struct Instance<'a, T: 'a + Clone + Debug + Send + Sync> { impl<'a, T: Clone + Debug + Eq + Hash + Send + Sync + Into> + From> + AsRef<[u8]>> Instance<'a, T> -where Vec: From { pub fn new(tx: &'a Sender>, rx: &'a Receiver>, @@ -122,14 +121,13 @@ fn send_shards<'a, T>(value: T, Result, Error> where T: Clone + Debug + Send + Sync + Into> + From> + AsRef<[u8]> - , Vec: From { let data_shard_num = coding.data_shard_count(); let parity_shard_num = coding.parity_shard_count(); debug!("Data shards: {}, parity shards: {}", data_shard_num, parity_shard_num); - let mut v: Vec = Vec::from(value); + let mut v: Vec = T::into(value); let value_len = v.len(); // Size of a Merkle tree leaf value, in bytes. let shard_len = if value_len % data_shard_num > 0 { @@ -210,7 +208,6 @@ fn inner_run<'a, T>(tx: &'a Sender>, Result> where T: Clone + Debug + Eq + Hash + Send + Sync + Into> + From> + AsRef<[u8]> - , Vec: From { // Erasure coding scheme: N - 2f value shards and 2f parity shards let parity_shard_num = 2 * num_faulty_nodes; @@ -236,7 +233,7 @@ where T: Clone + Debug + Eq + Hash + Send + Sync + Into> if proof.validate(h.as_slice()) { // Save the leaf value for reconstructing the tree later. leaf_values[index_of_proof(&proof)] = - Some(Vec::from(proof.value.clone()) + Some(T::into(proof.value.clone()) .into_boxed_slice()); leaf_values_num = leaf_values_num + 1; root_hash = Some(h); @@ -280,7 +277,7 @@ where T: Clone + Debug + Eq + Hash + Send + Sync + Into> // Save the leaf value for reconstructing the tree // later. leaf_values[index_of_proof(&p)] = - Some(Vec::from(p.value.clone()) + Some(T::into(p.value.clone()) .into_boxed_slice()); leaf_values_num = leaf_values_num + 1; } @@ -309,7 +306,7 @@ where T: Clone + Debug + Eq + Hash + Send + Sync + Into> // Save the leaf value for reconstructing the tree // later. leaf_values[index_of_proof(&p)] = - Some(Vec::from(p.value.clone()) + Some(T::into(p.value.clone()) .into_boxed_slice()); leaf_values_num = leaf_values_num + 1; @@ -400,8 +397,8 @@ fn decode_from_shards(leaf_values: &mut Vec>>, data_shard_num: usize, root_hash: &Vec) -> Result> -where T: Clone + Debug + Send + Sync + AsRef<[u8]> + From>, -Vec: From +where T: Clone + Debug + Send + Sync + AsRef<[u8]> + From> + + Into> { // Try to interpolate the Merkle tree using the Reed-Solomon erasure coding // scheme. @@ -437,7 +434,7 @@ Vec: From /// type `T`. This is useful for reconstructing the data value held in the tree /// and forgetting the leaves that contain parity information. fn glue_shards(m: MerkleTree, n: usize) -> T -where T: From>, Vec: From +where T: From> + Into> { let mut t: Vec = Vec::new(); let mut i = 0; @@ -447,7 +444,7 @@ where T: From>, Vec: From if i > n { break; } - for b in Vec::from(s).into_iter() { + for b in T::into(s).into_iter() { t.push(b); } } diff --git a/src/node.rs b/src/node.rs index 6cf6c75..76e4325 100644 --- a/src/node.rs +++ b/src/node.rs @@ -37,9 +37,9 @@ pub struct Node { value: Option } -impl> + AsRef<[u8]>> +impl> + Into> + + AsRef<[u8]>> Node -where Vec: From { /// Consensus node constructor. It only initialises initial parameters. pub fn new(addr: SocketAddr, @@ -83,7 +83,7 @@ where Vec: From { Ok(t) => { debug!("Broadcast instance 0 succeeded: {}", - String::from_utf8(Vec::from(t)).unwrap()); + String::from_utf8(T::into(t)).unwrap()); }, Err(e) => error!("Broadcast instance 0: {:?}", e) } @@ -125,7 +125,7 @@ where Vec: From Ok(t) => { debug!("Broadcast instance {} succeeded: {}", node_index, - String::from_utf8(Vec::from(t)).unwrap()); + String::from_utf8(T::into(t)).unwrap()); }, Err(e) => error!("Broadcast instance {}: {:?}", node_index, e)