Merge pull request #41 from gavofyork/bytes_ref

bytes_ref
This commit is contained in:
Gav Wood 2016-01-13 15:38:52 +01:00
commit dca7c65345

View File

@ -39,6 +39,7 @@ use std::fmt;
use std::slice;
use std::cmp::Ordering;
use std::error::Error as StdError;
use std::ops::{Deref, DerefMut};
use uint::{U128, U256};
use hash::FixedHash;
@ -89,6 +90,31 @@ impl ToPretty for Bytes {
}
}
pub enum BytesRef<'a> {
Flexible(&'a mut Bytes),
Fixed(&'a mut [u8])
}
impl<'a> Deref for BytesRef<'a> {
type Target = [u8];
fn deref(&self) -> &[u8] {
match self {
&BytesRef::Flexible(ref bytes) => bytes,
&BytesRef::Fixed(ref bytes) => bytes
}
}
}
impl <'a> DerefMut for BytesRef<'a> {
fn deref_mut(&mut self) -> &mut [u8] {
match self {
&mut BytesRef::Flexible(ref mut bytes) => bytes,
&mut BytesRef::Fixed(ref mut bytes) => bytes
}
}
}
/// Vector of bytes
pub type Bytes = Vec<u8>;
@ -436,4 +462,4 @@ fn populate_big_types() {
let mut h = h256_from_u64(0x69);
h.copy_raw_from(&a);
assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000069"));
}
}