Manually implement Clone and Debug for Buffer

fix #10
This commit is contained in:
Kogia-sima 2020-06-12 14:52:26 +09:00
parent 6ac39eee4c
commit 1fa5186e34
1 changed files with 17 additions and 1 deletions

View File

@ -10,7 +10,6 @@ const MEMORY_LAYOUT: Layout = unsafe { Layout::from_size_align_unchecked(1, 1) }
///
/// This struct is quite simular to `String`, but some methods are
/// re-implemented for faster buffering.
#[derive(Clone, Debug)]
pub struct Buffer {
data: *mut u8,
len: usize,
@ -136,6 +135,23 @@ impl Buffer {
}
}
impl Clone for Buffer {
fn clone(&self) -> Self {
let layout = unsafe { alloc(Layout::from_size_align_unchecked(self.len, 1)) };
Self {
data: layout,
len: self.len,
capacity: self.len,
}
}
}
impl fmt::Debug for Buffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_str().fmt(f)
}
}
impl Drop for Buffer {
fn drop(&mut self) {
if !self.data.is_null() {