bytes32/
lib.rs

1//! Contains a custom type definition for a 32-bit-wide byte array. 
2//! 
3//! To do: maybe integrate with other crates e.g. ethcore-bytes, or further tune
4//! it e.g. with a wrapper for input and output.
5
6use std::cmp::Ordering;
7
8#[derive(Eq, PartialEq)]
9/// Creates a custom Bytes32 type, a 4 byte wide vector.
10struct Bytes32<'a> {
11   pub store: Vec<[&'a u8; 4]>, 
12}
13
14
15impl<'a> Ord for Bytes32<'a> {
16    fn cmp(&self, other: &Bytes32) -> Ordering {
17
18        for _i in 0..3 {
19            if other.store[_i] > self.store[_i] {
20                return Ordering::Greater;
21            }
22            if other.store[_i] < self.store[_i] {
23                return Ordering::Less;
24            }
25        }
26        Ordering::Equal
27    }
28}
29
30impl<'a> PartialOrd for Bytes32<'a> {
31    fn partial_cmp(&self, other: &Bytes32) -> Option<Ordering> {
32        Some(self.cmp(other))
33    }
34}