[][src]Struct ioslice::IoSliceMut

#[repr(transparent)]pub struct IoSliceMut<'a, I: Initialization = Initialized> { /* fields omitted */ }

A #![no_std]-friendly wrapper over the std::io::IoSliceMut.

Internally, the struct will store the following based on crate features:

  • std - wrapping std::io::IoSliceMut directly, with accessors for it as well as conversion functions and From impls.
  • libc (with #[cfg(unix)] - wrapping libc::iovec directly on platforms that support it, together with a marker making rustc think this stores a &'a mut [u8].
  • (none) - wrapping a regular slice, that may not have the same ABI guarantees as the types from std or libc have.

Implementations

impl<'a, I: Initialization> IoSliceMut<'a, I>[src]

pub fn new(slice: &'a mut [u8]) -> Self[src]

Construct a new mutable I/O slice, from an existing initialized slice. The initializedness is determined based on the generic parameter I, while the original slice obviously has to be initialized since its type is u8 and not [MaybeUninit<u8>].

pub unsafe fn assume_init(self) -> IoSliceMut<'a, Initialized>[src]

Unsafely cast a possibly uninitialized slice into an initialized slice.

NOTE: THIS MUST NOT BE USED FOR INITIALIZATION; THAT IS DIRECT UB

Safety

For this to be safe, the initialization invariant must be upheld. Refer to the std::mem::MaybeUninit docs.

pub unsafe fn assume_init_ref(&self) -> &IoSliceMut<'a, Initialized>[src]

Unsafely cast a possibly uninitialized slice into an initialized slice, by reference.

Safety

This must uphold the initialization invariant.

pub unsafe fn assume_init_mut(&mut self) -> &mut IoSliceMut<'a, Initialized>[src]

Unsafely cast a possibly uninitialized slice into an initialized slice, by mutable reference.

Safety

This must uphold the initialization invariant.

pub fn into_uninit(self) -> IoSliceMut<'a, Uninitialized>[src]

Cast an I/O slice, being Initialized or not, into an Uninitialized I/O slice.

pub fn as_uninit(&self) -> &IoSliceMut<'a, Uninitialized>[src]

Cast an I/O slice, being Initialized or not, into an Uninitialized I/O slice, by reference.

pub fn as_uninit_mut(&mut self) -> &mut IoSliceMut<'a, Uninitialized>[src]

Cast an I/O slice, being Initialized or not, into an Uninitialized I/O slice, by mutable reference.

pub unsafe fn from_raw_iovec(slice: iovec) -> Self[src]

Wrap a system libc::iovec into this wrapper.

This is only available on Unix targets with the libc feature enabled.

Safety

For this to be safe, the validity invariant must be upheld, which takes things like size, alignment, concurrent use, etc. in parallel. In short, the slice must be considered mutably borrowed, and it must be safe to assume that it will not outlive the lifetime 'a. Refer to the std::ptr docs for more information regarding validity.

Additionally, if the I generic parameter is Initialized, the iovec must also point to initialized data.

pub fn as_raw_iovec(&self) -> iovec[src]

Retrieve the wrapped raw `libc::iovec from this wrapper.

The resulting slice is considered immutable, even though it is neither UB nor more unsafe than as_raw_iovecs_mut. This simply exists to prevent accidentally obtaining a "mutable" libc::iovec where that is not possible (e.g. inside an std::sync::Arc).

pub fn as_raw_iovec_mut(&mut self) -> iovec[src]

Retrieve the wrapped raw `libc::iovec from this wrapper, requiring exclusive access of this slice, to obtain.

pub fn cast_to_raw_iovecs(slices: &[Self]) -> &[iovec][src]

Cast a slice of wrapped I/O slices into a slice of libc::iovecs.

pub unsafe fn cast_to_raw_iovecs_mut(slices: &mut [Self]) -> &mut [iovec][src]

Unsafely cast a mutable slice of wrapped I/O slices into a mutable slice of libc::iovecs.

Safety

This is unsafe because the initialization or validity invariants may be broken since the iovecs can be changed arbitrarily in a mutable reference.

pub unsafe fn from_raw_iovecs(slice: &[iovec]) -> &[Self][src]

Unsafely cast a slice of libc::iovecs into a slice of IoSliceMut.

Safety

This is unsafe since the iovecs must uphold the validity and initialization invariants.

pub unsafe fn from_raw_iovecs_mut(slice: &mut [iovec]) -> &mut [Self][src]

Unsafely cast a mutable slice of libc::iovecs into a mutable slice of IoSliceMut.

Safety

This is unsafe since the iovecs must uphold the validity and initialization invariants.

pub fn advance(&mut self, count: usize)[src]

Advance the start offset of a single slice by count bytes, reducing the length as well.

Panics

This will panic if count is greater than the current length.

#[must_use]pub fn advance_within(slices: &mut [Self], n: usize) -> Option<&mut [Self]>[src]

Advance multiple slices by n, skipping and truncating slices until there are n less total bytes.

They are always advanced from start to end, and only the last slice will actually be changed if the count turned out to be uneven. None is returned if n turns out to be greater than the total length of the slices, so that counting beforehand becomes unnecessary.

pub fn inner_data(&self) -> &[I::DerefTargetItem][src]

Retrieve the "inner data" immutably, pointed to by the I/O slice, being to either &[u8] or &[MaybeUninit<u8>] depending on the generic type parameter I.

pub fn inner_data_mut(&mut self) -> &mut [I::DerefTargetItem][src]

Retrieve the "inner data" mutably, pointed to by the I/O slice, being to either &mut [u8] or &mut [MaybeUninit<u8>] depending on the generic type parameter I.

pub fn into_inner_data(self) -> &'a mut [I::DerefTargetItem][src]

Get the "inner data" mutably, but with the lifetime 'a rather than the lifetime of self.

pub fn from_inner_data(inner_data: &'a mut [I::DerefTargetItem]) -> Self[src]

Convert a regular slice that points to either u8 or MaybeUninit<u8>, into IoSliceMut.

pub fn as_maybe_uninit_slice(&self) -> &[MaybeUninit<u8>][src]

pub fn as_maybe_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>][src]

#[must_use]pub fn zeroed(self) -> IoSliceMut<'a, Initialized>[src]

#[must_use]pub fn zeroed_by_ref<'b>(&'b mut self) -> &'b mut IoSliceMut<'a, Initialized>[src]

impl<'a> IoSliceMut<'a, Initialized>[src]

pub fn as_slice(&self) -> &[u8][src]

Retrieve the inner slice immutably. This requires the I/O slice to be initialized.

Unlike the immutable IoSlice, this will require a secondary lifetime of self, to prevent aliasing when the data can be mutated. If it is necessary to obtain a byte slice with lifetime 'a, use to_slice.

pub fn into_slice(self) -> &'a [u8][src]

Take an IoSliceMut by value, turning it into an immutable byte slice of lifetime 'a.

pub fn as_slice_mut(&mut self) -> &mut [u8][src]

Retrieve the inner slice mutably. This requires the I/O slice to be initialized.

Note that unlike into_slice_mut, this will have the lifetime of self, not 'a.

pub fn into_slice_mut(self) -> &'a mut [u8][src]

Take an IoSliceMut by value, turning it into a mutable byte slice of lifetime 'a.

pub fn cast_to_std_ioslices<'b>(slices: &'b [Self]) -> &'b [IoSlice<'a>][src]

Cast &[IoSliceMut] to &[std::io::IoSlice].

pub fn cast_to_std_mut_ioslices<'b>(slices: &'b [Self]) -> &'b [IoSliceMut<'a>][src]

Cast &[IoSliceMut] to &[std::io::IoSliceMut].

pub fn cast_to_std_ioslices_mut<'b>(
    slices: &'b mut [Self]
) -> &'b mut [IoSlice<'a>]
[src]

Cast &mut [IoSliceMut] to &mut [std::io::IoSlice].

pub fn cast_to_std_mut_ioslices_mut(
    slices: &'a mut [Self]
) -> &'a mut [IoSliceMut<'a>]
[src]

Cast &mut [IoSliceMut] to &mut [std::io::IoSliceMut].

Trait Implementations

impl<'a, I: Initialization> AsMut<[<I as Initialization>::DerefTargetItem]> for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> AsRef<[<I as Initialization>::DerefTargetItem]> for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Borrow<[<I as Initialization>::DerefTargetItem]> for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> BorrowMut<[<I as Initialization>::DerefTargetItem]> for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Debug for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Deref for IoSliceMut<'a, I>[src]

type Target = [I::DerefTargetItem]

The resulting type after dereferencing.

impl<'a, I: Initialization> DerefMut for IoSliceMut<'a, I>[src]

impl<'a> Eq for IoSliceMut<'a, Initialized>[src]

impl<'a, I: Initialization> From<&'a mut [<I as Initialization>::DerefTargetItem]> for IoSliceMut<'a, I>[src]

impl<'a> From<&'a mut [u8]> for IoSliceMut<'a, Uninitialized>[src]

impl<'a, I: Initialization> From<IoSliceMut<'a, I>> for iovec[src]

impl<'a> Hash for IoSliceMut<'a, Initialized>[src]

impl<'a> Ord for IoSliceMut<'a, Initialized>[src]

impl<'a> PartialEq<[u8]> for IoSliceMut<'a, Initialized>[src]

impl<'a, 'b> PartialEq<IoSlice<'b, Initialized>> for IoSliceMut<'a, Initialized>[src]

impl<'a> PartialEq<IoSliceMut<'a, Initialized>> for IoSliceMut<'a, Initialized>[src]

impl<'a> PartialEq<IoSliceMut<'a, Initialized>> for IoBox[src]

impl<'a, 'b> PartialEq<IoSliceMut<'b, Initialized>> for IoSlice<'a, Initialized>[src]

impl<'a> PartialOrd<[u8]> for IoSliceMut<'a, Initialized>[src]

impl<'a, 'b> PartialOrd<IoSlice<'b, Initialized>> for IoSliceMut<'a, Initialized>[src]

impl<'a> PartialOrd<IoSliceMut<'a, Initialized>> for IoSliceMut<'a, Initialized>[src]

impl<'a, 'b> PartialOrd<IoSliceMut<'b, Initialized>> for IoSlice<'a, Initialized>[src]

impl<'a, I: Initialization> RefUnwindSafe for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Send for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Sync for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> Unpin for IoSliceMut<'a, I>[src]

impl<'a, I: Initialization> UnwindSafe for IoSliceMut<'a, I>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.