Additional Populatable API tweaks.

This commit is contained in:
Gav Wood 2016-01-08 11:52:46 +01:00
parent f0da76df7c
commit 3018c4a28a
3 changed files with 5 additions and 10 deletions

View File

@ -10,19 +10,18 @@ use rustc_serialize::hex::*;
use error::EthcoreError; use error::EthcoreError;
use rand::Rng; use rand::Rng;
use rand::os::OsRng; use rand::os::OsRng;
use bytes::BytesConvertable; use bytes::{BytesConvertable,Populatable};
use math::log2; use math::log2;
use uint::U256; use uint::U256;
/// Trait for a fixed-size byte array to be used as the output of hash functions. /// Trait for a fixed-size byte array to be used as the output of hash functions.
/// ///
/// Note: types implementing `FixedHash` must be also `BytesConvertable`. /// Note: types implementing `FixedHash` must be also `BytesConvertable`.
pub trait FixedHash: Sized + BytesConvertable { pub trait FixedHash: Sized + BytesConvertable + Populatable {
fn new() -> Self; fn new() -> Self;
fn random() -> Self; fn random() -> Self;
fn randomize(&mut self); fn randomize(&mut self);
fn size() -> usize; fn size() -> usize;
fn as_slice_mut(&mut self) -> &mut [u8];
fn from_slice(src: &[u8]) -> Self; fn from_slice(src: &[u8]) -> Self;
fn clone_from_slice(&mut self, src: &[u8]) -> usize; fn clone_from_slice(&mut self, src: &[u8]) -> usize;
fn shift_bloom<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash; fn shift_bloom<'a, T>(&'a mut self, b: &T) -> &'a mut Self where T: FixedHash;
@ -78,10 +77,6 @@ macro_rules! impl_hash {
$size $size
} }
fn as_slice_mut(&mut self) -> &mut [u8] {
&mut self.0
}
// TODO: remove once slice::clone_from_slice is stable // TODO: remove once slice::clone_from_slice is stable
#[inline] #[inline]
fn clone_from_slice(&mut self, src: &[u8]) -> usize { fn clone_from_slice(&mut self, src: &[u8]) -> usize {

View File

@ -2,8 +2,8 @@
use std::mem::uninitialized; use std::mem::uninitialized;
use tiny_keccak::Keccak; use tiny_keccak::Keccak;
use bytes::BytesConvertable; use bytes::{BytesConvertable,Populatable};
use hash::{FixedHash, H256}; use hash::H256;
/// Types implementing this trait are sha3able. /// Types implementing this trait are sha3able.
/// ///

View File

@ -668,7 +668,7 @@ mod tests {
use env_logger; use env_logger;
use rand::random; use rand::random;
use std::collections::HashSet; use std::collections::HashSet;
use bytes::{ToPretty,Bytes}; use bytes::{ToPretty,Bytes,Populatable};
use super::super::node::*; use super::super::node::*;
use super::super::trietraits::*; use super::super::trietraits::*;