diff --git a/src/buf.rs b/src/buf.rs index 24b4c59..2f43135 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -1,9 +1,11 @@ use std::alloc::{alloc, dealloc, Layout}; use std::io::Write; use std::mem::size_of; +use std::ops::{Index, IndexMut}; use std::ptr::{ copy_nonoverlapping, drop_in_place, slice_from_raw_parts, slice_from_raw_parts_mut, write_bytes, NonNull, }; +use std::slice::SliceIndex; use std::sync::Mutex; const INDIVIDUAL_BUFFER_ALIGN: usize = size_of::(); @@ -114,6 +116,21 @@ impl Buf { } } +impl> Index for Buf { + type Output = I::Output; + + #[inline] + fn index(&self, index: I) -> &Self::Output { + Index::index(self.as_ref(), index) + } +} +impl> IndexMut for Buf { + fn index_mut(&mut self, index: I) -> &mut Self::Output { + IndexMut::index_mut(self.as_mut(), index) + } +} + + impl AsRef<[u8]> for Buf { #[inline(always)] fn as_ref(&self) -> &[u8] {