#[repr(transparent)]pub struct IoBufMut<'a> {
iobuf: IoBuf,
phantom: PhantomData<&'a mut [u8]>,
}
Expand description
Cross-platform mutable buffer.
This type is essentialy std::io::IoSliceMut
, and guaranteed to be ABI-compatible with
libc::iovec
on Linux/WSABUF
on Windows; however, it does NOT automatically deref to &mut [u8]
, which is critical because it can point to guest memory. (Guest memory is implicitly
mutably borrowed by the guest, so another mutable borrow would violate Rust assumptions about
references.)
Fields§
§iobuf: IoBuf
§phantom: PhantomData<&'a mut [u8]>
Implementations§
source§impl<'a> IoBufMut<'a>
impl<'a> IoBufMut<'a>
pub fn new(buf: &mut [u8]) -> IoBufMut<'a>
sourcepub unsafe fn from_raw_parts(addr: *mut u8, len: usize) -> IoBufMut<'a>
pub unsafe fn from_raw_parts(addr: *mut u8, len: usize) -> IoBufMut<'a>
Creates a IoBufMut
from a pointer and a length.
§Safety
In order to use this method safely, addr
must be valid for reads and writes of len
bytes
and should live for the entire duration of lifetime 'a
.
sourcepub unsafe fn from_iobuf(iobuf: IoBuf) -> IoBufMut<'a>
pub unsafe fn from_iobuf(iobuf: IoBuf) -> IoBufMut<'a>
Creates a IoBufMut
from an IoBuf.
§Safety
In order to use this method safely, iobuf
must be valid for reads and writes through its
length and should live for the entire duration of lifetime 'a
.
sourcepub fn advance(&mut self, count: usize)
pub fn advance(&mut self, count: usize)
Advance the internal position of the buffer.
Panics if count > self.len()
.
sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shorten the length of the buffer.
Has no effect if len > self.len()
.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
sourcepub fn as_mut_ptr(&self) -> *mut u8
pub fn as_mut_ptr(&self) -> *mut u8
Gets a mutable pointer to this slice’s memory.
sourcepub fn as_iobufs<'slice>(iovs: &'slice [IoBufMut<'_>]) -> &'slice [IoBuf]
pub fn as_iobufs<'slice>(iovs: &'slice [IoBufMut<'_>]) -> &'slice [IoBuf]
Converts a slice of IoBufMut
s into a slice of IoBuf
s.
sourcepub fn as_iobufs_mut<'slice>(
iovs: &'slice mut [IoBufMut<'_>]
) -> &'slice mut [IoBuf]
pub fn as_iobufs_mut<'slice>( iovs: &'slice mut [IoBufMut<'_>] ) -> &'slice mut [IoBuf]
Converts a mutable slice of IoBufMut
s into a mutable slice of IoBuf
s.