bytes_ref

This commit is contained in:
debris 2016-01-13 15:14:24 +01:00
parent 4650961a5a
commit df3e3edc8a

View File

@ -39,6 +39,7 @@ use std::fmt;
use std::slice; use std::slice;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::error::Error as StdError; use std::error::Error as StdError;
use std::ops::{Deref, DerefMut};
use uint::{U128, U256}; use uint::{U128, U256};
use hash::FixedHash; 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 /// Vector of bytes
pub type Bytes = Vec<u8>; pub type Bytes = Vec<u8>;