use core::fmt;
use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::slice;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Iovec<'a> {
ptr: *const u8,
len: usize,
_p: PhantomData<&'a [u8]>,
}
impl<'a> Iovec<'a> {
#[inline(always)]
pub fn new(buf: &'a [u8]) -> Self {
Self { ptr: buf.as_ptr(), len: buf.len(), _p: PhantomData }
}
#[inline(always)]
pub fn as_slice(&self) -> &'a [u8] {
unsafe { slice::from_raw_parts(self.ptr, self.len) }
}
}
impl fmt::Debug for Iovec<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.as_slice(), f)
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct IovecMut<'a> {
ptr: *mut MaybeUninit<u8>,
len: usize,
_p: PhantomData<&'a mut [u8]>,
}
impl<'a> IovecMut<'a> {
#[inline(always)]
pub fn new(buf: &'a mut [MaybeUninit<u8>]) -> Self {
Self { ptr: buf.as_mut_ptr(), len: buf.len(), _p: PhantomData }
}
#[inline(always)]
pub fn as_slice(&self) -> &'a [MaybeUninit<u8>] {
unsafe { slice::from_raw_parts(self.ptr, self.len) }
}
#[inline(always)]
pub fn as_mut_slice(&mut self) -> &'a mut [MaybeUninit<u8>] {
unsafe { slice::from_raw_parts_mut(self.ptr, self.len) }
}
}
impl fmt::Debug for IovecMut<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.as_slice(), f)
}
}