Also implement Deref/DerefMut for MappedBuffer for &[u8]

This commit is contained in:
Sebastian Dröge 2017-12-13 10:55:26 +02:00
parent 85fdc8bf13
commit 5dff6026be

View file

@ -10,6 +10,7 @@ use std::ptr;
use std::mem;
use std::fmt;
use std::slice;
use std::ops;
use std::u64;
use std::usize;
use std::marker::PhantomData;
@ -479,6 +480,20 @@ impl AsMut<[u8]> for MappedBuffer<Writable> {
}
}
impl<T> ops::Deref for MappedBuffer<T> {
type Target = [u8];
fn deref(&self) -> &[u8] {
self.as_slice()
}
}
impl ops::DerefMut for MappedBuffer<Writable> {
fn deref_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 {