From f7ee9436cd9d5248a5acffb7fc8867d6653565d6 Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 18 Dec 2015 10:29:06 +0100 Subject: [PATCH 1/4] more convinient creation of uint --- src/uint.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 { From 72a24ad023a318909c32251b972067edf8bdc5c6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 20 Dec 2015 12:28:13 +0000 Subject: [PATCH 2/4] SemanticVersion struct. Additional documentation. --- src/lib.rs | 1 + src/semantic_version.rs | 28 ++++++++++++++++++++++++++++ src/trie/journal.rs | 4 ++++ 3 files changed, 33 insertions(+) create mode 100644 src/semantic_version.rs diff --git a/src/lib.rs b/src/lib.rs index 9120f0977..4859a8580 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,5 +66,6 @@ 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..026902263 --- /dev/null +++ b/src/semantic_version.rs @@ -0,0 +1,28 @@ +/// A version value with strict meaning. Use `to_u32` to convert to a simple integer. +/// +/// # Example +/// ``` +/// extern crate ethcore; +/// use ethcore::engine::*; +/// 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}; From be2b041ee4d0166aa96222ea0c6602dc516c46e1 Mon Sep 17 00:00:00 2001 From: debris Date: Mon, 21 Dec 2015 01:57:34 +0100 Subject: [PATCH 3/4] fixed semantic version tests --- src/semantic_version.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/semantic_version.rs b/src/semantic_version.rs index 026902263..92f6ea376 100644 --- a/src/semantic_version.rs +++ b/src/semantic_version.rs @@ -2,8 +2,9 @@ /// /// # Example /// ``` -/// extern crate ethcore; -/// use ethcore::engine::*; +/// extern crate ethcore_util as util; +/// use util::semantic_version::*; +/// /// fn main() { /// assert_eq!(SemanticVersion::new(1, 2, 3).as_u32(), 0x010203); /// } From 9220e0c49f7ae44c1118abee7b81e75697fcb067 Mon Sep 17 00:00:00 2001 From: debris Date: Mon, 21 Dec 2015 02:30:38 +0100 Subject: [PATCH 4/4] missing Error case --- src/error.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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);*/