mirror of
https://github.com/zerotier/common-utils.git
synced 2026-05-22 16:28:56 -07:00
added indexing
This commit is contained in:
+17
@@ -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::<u32>();
|
||||
@@ -114,6 +116,21 @@ impl Buf {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: SliceIndex<[u8]>> Index<I> for Buf {
|
||||
type Output = I::Output;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: I) -> &Self::Output {
|
||||
Index::index(self.as_ref(), index)
|
||||
}
|
||||
}
|
||||
impl<I: SliceIndex<[u8]>> IndexMut<I> 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] {
|
||||
|
||||
Reference in New Issue
Block a user