[][src]Struct ioslice::IoSlice

#[repr(transparent)]pub struct IoSlice<'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::IoSlice 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.
  • winapi (with #[cfg(windows)]) - wrapping WSABUF directly.
  • (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> IoSlice<'a, I>[src]

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

Convert a regular slice into an I/O slice.

The initializedness of the resulting I/O slice is dependent on the I generic parameter, which by default is Initialized. Note that it is highly recommended not to call this with Uninitialized, since immutable slices cannot be made initialized, and one therefore has to prove externally that the memory is in fact initialized before using it.

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

Cast any I/O slice into an Uninitialized slice, forgetting about the original initializedness.

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

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

Turn any I/O slice into an Uninitialized slice, forgetting about the original initializedness.

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

Unsafely turn an I/O slice, being already Initialized or not, into an I/O slice that is Initialized.

Safety

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

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

Wrap a system libc::iovec into a wrapped I/O slice, assuming the iovec can be represented as borrowed for the lifetime 'a. If the iovec is otherwise owned and allocated via the system allocator, consider wrapping it in IoBox if the alloc feature is used.

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

Safety

This is unsafe because the slice must be valid (refer to libstd's section about pointer and slice validity near std::ptr).

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

Retrieve the inner iovec from this I/O slice.

The raw iovec must be considered borrowed from this slice, even though it is not tracked with a lifetime.

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

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

Cast a slice of I/O slices into a slice of iovecs. Since these must share the same ABI layout, this is completely safe, and can be directly passed to system calls.

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

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

Cast a mutable slice of I/O slices into a mutable slice of iovecs. iovecs share the exact same ABI guarantees as this wrapper.

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

Safety

This is unsafe, since the iovecs can be mutated, which will cause the original wrapped slices to be changed as well. If the iovecs are changed to invalid values in any way, this breaks the validity invariant upheld by this wrapped type, leading to UB.

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

Advance the start offset of an I/O slice, effectively shrinking it from the start.

Panics

This will panic if count is greater than the current length. On Windows, this will also therefore instantly fail if count is greater than 2^32, since larger buffers cannot be constructed.

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

Advance a range of slices by a specific offset, by advancing each slice individually until the offset is reached.

Note that while this may modify the original slices in-place, the return value should always be used, since the original value may contain old slices that were completely skipped and never made empty.

This returns an Option rather than panicking when n is greater than the total length, to reduce the need for counting, or blind reliance on system call correctness.

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

Get a slice to the "inner data" pointed to by this slice, which may be either [u8] or [MaybeUninit<u8>], depending on the I generic parameter. Prefer as_slice or as_maybe_uninit_slice instead; this is only used to make various methods easier to implement generically.

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

Construct an I/O slice based on the inner data, which is either [u8] or [MaybeUninit].

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

Retrieve a slice of possibly uninitialized data, but which is still always valid.

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

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

Retrieve an initialized byte slice from this I/O slice.

pub fn into_std_ioslice(self) -> IoSlice<'a>[src]

Convert this slice into an initialized std::io::IoSlice.

This is only available with the std feature enabled.

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

Cast a slice of I/O slices, into a slice of libstd's std::io::IoSlice. This is safe since they both must share the same ABI layout as libc::iovec.

This is only available with the std feature enabled.

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

Cast a mutable slice of I/O slices, into a mutable slice of libstd's std::io::IoSlice. This is safe since they both must share the same ABI layout as libc::iovec, and since libstd's I/O slices have the same validity invariant as this wrapper and slices in general.

This is only available with the std feature enabled.

Trait Implementations

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

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

impl<'a, I: Clone + Initialization> Clone for IoSlice<'a, I> where
    I::DerefTargetItem: Clone
[src]

impl<'a, I: Copy + Initialization> Copy for IoSlice<'a, I> where
    I::DerefTargetItem: Copy
[src]

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

impl<'a, I: Initialization> Default for IoSlice<'a, I>[src]

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

type Target = [I::DerefTargetItem]

The resulting type after dereferencing.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<'a, I: Initialization> UnwindSafe for IoSlice<'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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.