Merge pull request #128 from aturon/from_vec

Add From<Vec<u8>> and Clone impls to EasyBuf
This commit is contained in:
Alex Crichton
2016-12-17 14:27:40 -08:00
committed by GitHub
+12
View File
@@ -12,6 +12,7 @@ use io::Io;
/// be handed out efficiently, each with a `'static` lifetime which keeps the
/// data alive. The buffer also supports mutation but may require bytes to be
/// copied to complete the operation.
#[derive(Clone)]
pub struct EasyBuf {
buf: Arc<Vec<u8>>,
start: usize,
@@ -177,6 +178,17 @@ impl<'a> DerefMut for EasyBufMut<'a> {
}
}
impl From<Vec<u8>> for EasyBuf {
fn from(vec: Vec<u8>) -> EasyBuf {
let end = vec.len();
EasyBuf {
buf: Arc::new(vec),
start: 0,
end: end,
}
}
}
impl<'a> Drop for EasyBufMut<'a> {
fn drop(&mut self) {
*self.end = self.buf.len();