added clone to ByteBuf and BytesMut along with simple clone test

This commit is contained in:
Rick Richardson
2016-11-21 15:43:59 -08:00
parent 12d0804f17
commit 2b796d40e9
3 changed files with 35 additions and 1 deletions
+10
View File
@@ -215,3 +215,13 @@ impl fmt::Write for ByteBuf {
fmt::write(self, args)
}
}
impl Clone for ByteBuf {
fn clone(&self) -> Self {
ByteBuf {
mem: self.mem.clone(),
rd: self.rd,
}
}
}
+13
View File
@@ -558,3 +558,16 @@ impl<'a, T: ?Sized> PartialEq<&'a T> for Bytes
*self == **other
}
}
impl Clone for BytesMut {
fn clone(&self) -> BytesMut {
let mut v = Vec::with_capacity(self.len());
v.extend_from_slice(&self[..]);
BytesMut {
mem: Mem { inner : Arc::new(UnsafeCell::new(v.into_boxed_slice())) },
pos: self.pos,
len: self.len,
cap: self.cap,
}
}
}