Implement AsRef<[u8]>, AsMut, Debug, PartialEq and Eq for MappedBuffer

This commit is contained in:
Sebastian Dröge 2017-12-13 09:58:41 +02:00
parent f2eabaddf7
commit 85fdc8bf13

View file

@ -467,6 +467,18 @@ impl MappedBuffer<Writable> {
}
}
impl<T> AsRef<[u8]> for MappedBuffer<T> {
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}
impl AsMut<[u8]> for MappedBuffer<Writable> {
fn as_mut(&mut self) -> &mut [u8] {
self.as_mut_slice()
}
}
impl<T> Drop for MappedBuffer<T> {
fn drop(&mut self) {
if let Some(ref buffer) = self.buffer {
@ -477,6 +489,22 @@ impl<T> Drop for MappedBuffer<T> {
}
}
impl<T> fmt::Debug for MappedBuffer<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("MappedBuffer")
.field(&self.get_buffer())
.finish()
}
}
impl<T> PartialEq for MappedBuffer<T> {
fn eq(&self, other: &MappedBuffer<T>) -> bool {
self.get_buffer().eq(other.get_buffer())
}
}
impl<T> Eq for MappedBuffer<T> {}
unsafe impl<T> Send for MappedBuffer<T> {}
#[cfg(test)]