diff --git a/src/error.rs b/src/error.rs index 71514d045..e41bcd178 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,6 +13,7 @@ pub enum EthcoreError { FromHex(FromHexError), BaseData(BaseDataError), BadSize, + UnknownName } impl From for EthcoreError { @@ -39,4 +40,4 @@ macro_rules! assimilate { ) } assimilate!(FromHex); -assimilate!(BaseData);*/ \ No newline at end of file +assimilate!(BaseData);*/ diff --git a/src/lib.rs b/src/lib.rs index 3a93bed98..a061a72cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,7 @@ pub mod trie; pub mod nibbleslice; pub mod heapsizeof; pub mod squeeze; +pub mod semantic_version; pub mod network; diff --git a/src/semantic_version.rs b/src/semantic_version.rs new file mode 100644 index 000000000..92f6ea376 --- /dev/null +++ b/src/semantic_version.rs @@ -0,0 +1,29 @@ +/// A version value with strict meaning. Use `to_u32` to convert to a simple integer. +/// +/// # Example +/// ``` +/// extern crate ethcore_util as util; +/// use util::semantic_version::*; +/// +/// fn main() { +/// assert_eq!(SemanticVersion::new(1, 2, 3).as_u32(), 0x010203); +/// } +/// ``` +pub struct SemanticVersion { + /// Major version - API/feature removals & breaking changes. + pub major: u8, + /// Minor version - API/feature additions. + pub minor: u8, + /// Tiny version - bug fixes. + pub tiny: u8, +} + +impl SemanticVersion { + /// Create a new object. + pub fn new(major: u8, minor: u8, tiny: u8) -> SemanticVersion { SemanticVersion{major: major, minor: minor, tiny: tiny} } + + /// Convert to a `u32` representation. + pub fn as_u32(&self) -> u32 { ((self.major as u32) << 16) + ((self.minor as u32) << 8) + self.tiny as u32 } +} + +// TODO: implement Eq, Comparison and Debug/Display for SemanticVersion. diff --git a/src/trie/journal.rs b/src/trie/journal.rs index 77efc991c..948f07a06 100644 --- a/src/trie/journal.rs +++ b/src/trie/journal.rs @@ -11,8 +11,11 @@ enum Operation { Delete(H256), } +/// How many insertions and removals were done in an `apply` operation. pub struct Score { + /// Number of insertions. pub inserts: usize, + /// Number of removals. pub removes: usize, } @@ -54,6 +57,7 @@ impl Journal { } } + /// Apply this journal to the HashDB `db` and return the number of insertions and removals done. pub fn apply(self, db: &mut HashDB) -> Score { trace!("applying {:?} changes", self.0.len()); let mut ret = Score{inserts: 0, removes: 0}; diff --git a/src/uint.rs b/src/uint.rs index 88ed49712..b8eccc4cc 100644 --- a/src/uint.rs +++ b/src/uint.rs @@ -97,6 +97,16 @@ macro_rules! construct_uint { } } + #[inline] + pub fn zero() -> $name { + From::from(0u64) + } + + #[inline] + pub fn one() -> $name { + From::from(1u64) + } + /// Multiplication by u32 fn mul_u32(self, other: u32) -> $name { let $name(ref arr) = self; @@ -125,6 +135,21 @@ macro_rules! construct_uint { impl_map_from!($name, u8, u64); impl_map_from!($name, u16, u64); impl_map_from!($name, u32, u64); + impl_map_from!($name, usize, u64); + + impl From for $name { + fn from(value: i64) -> $name { + match value >= 0 { + true => From::from(value as u64), + false => { panic!("Unsigned integer can't be created from negative value"); } + } + } + } + + impl_map_from!($name, i8, i64); + impl_map_from!($name, i16, i64); + impl_map_from!($name, i32, i64); + impl_map_from!($name, isize, i64); impl<'a> From<&'a [u8]> for $name { fn from(bytes: &[u8]) -> $name {