[][src]Struct ioslice::IoBox

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

An owned chunk of memory, that is ABI-compatible with libc::iovec or WSABUF, depending on the platform and Cargo features used.

This must be allocated via the system alloc; importing pointers from malloc(2) is currently not possible.

Implementations

impl<I: Initialization> IoBox<I>[src]

pub fn try_alloc_zeroed(length: usize) -> Result<Self, AllocationError>[src]

Attempt to allocate length bytes, which are initially set to zero.

This allocation may fail, but should not be used unless the global allocator actually does return null when there is no memory. This is generally not the case for userspace processes, where the kernel gives more memory than physically available, but is obviously useful in #![no_std].

Since the allocator may be able to already have zeroed blocks of memory, this should be preferred over manually initializing it using zeroed.

Panics

This associated function will panic on Windows platforms when using the winapi feature, if the length exceeds the WSABUF limit of 2^32 bytes. Always check beforehand; this will never be returned as a regular allocation error.

pub fn alloc_zeroed(length: usize) -> Self[src]

Allocate length bytes, which are initially set to zero.

Panics

This associated function will, like most other heap-allocated structures in the alloc crate, panic when there is no available memory left. On Windows platforms with using the winapi feature, this will also panic if the length exceeds the WSABUF limit of 2^32 bytes.

pub fn into_raw_parts(self) -> (*mut u8, usize)[src]

Turn the I/O box into the underlying pointer and size.

pub unsafe fn from_raw_parts(base: *mut I::DerefTargetItem, len: usize) -> Self[src]

Convert an underlying pointer and size, into an IoBox.

Safety

For this to be safe, the validity and initialization invariants must be held. In addition to that, the pointer must be allocated using the system allocator.

pub fn into_raw_iovec(self) -> iovec[src]

pub fn into_box(self) -> Box<[I::DerefTargetItem]>[src]

pub fn as_ioslice(&self) -> IoSlice<'_, I>[src]

pub fn as_ioslice_mut(&mut self) -> IoSliceMut<'_, I>[src]

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

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

pub fn cast_to_ioslices(these: &[Self]) -> &[IoSlice<'_, I>][src]

pub unsafe fn cast_to_ioslices_mut(these: &mut [Self]) -> &mut [IoSlice<'_, I>][src]

Cast &mut [IoBox] to &mut [IoSlice].

Safety

To avoid being able to change the pointers, which are likely going to be deallocated in this Drop code, unless they are changed back, this is marked as "unsafe".

Refer to cast_to_mut_ioslices_mut.

pub fn cast_to_mut_ioslices(these: &[Self]) -> &[IoSliceMut<'_, I>][src]

pub unsafe fn cast_to_mut_ioslices_mut(
    these: &mut [Self]
) -> &mut [IoSliceMut<'_, I>]
[src]

Cast &mut [IoBox] to &mut [IoSliceMut].

Safety

Since a mutable slice that mirrors these allows it to change the start offsets and advancing them in other ways (and even changing them to global variables etc.), this can cause the Drop code to cause UB. The caller must ensure that any pointers are changed back to what they were previously, before the drop code is run.

pub unsafe fn assume_init(self) -> IoBox<Initialized>[src]

Convert IoBox<_> into IoBox<Initialized>, assuming that the data is initialized.

Safety

This shall not be used for initializing data. In that case, initialize it manually via as_maybe_uninit_slice_mut, and then call this.

While the validity invariant is already upheld when creating this type, the caller must ensure that the data be initialized. Refer to the std::mem::MaybeUninit docs.

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

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

pub fn into_uninit(self) -> IoBox<Uninitialized>[src]

pub fn into_uninit_box(self) -> Box<[MaybeUninit<u8>]>[src]

impl IoBox<Uninitialized>[src]

pub fn try_alloc_uninit(
    length: usize
) -> Result<IoBox<Uninitialized>, AllocationError>
[src]

Attempt to allocate length bytes, returning either an uninitialized heap-allocated buffer, or an error if the allocator was unable to allocate that many bytes. Note that unless called in an #![no_std] environment, the OS will likely give more memory than physically present, so prefer alloc_uninit instead in that case.

Panics

This associated function will panic on Windows platforms when using the winapi feature, if the length exceeds the WSABUF limit of 2^32 bytes. Always check beforehand; this will never be returned as a regular allocation error.

pub fn alloc_uninit(length: usize) -> IoBox<Uninitialized>[src]

Allocate length uninitialized bytes.

Panics

This associated function will panic if out of memory, or if the length is greater than 2^32 on Windows platforms.

impl IoBox<Initialized>[src]

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

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

Trait Implementations

impl<I: Initialization> AsMut<[MaybeUninit<u8>]> for IoBox<I>[src]

impl AsMut<[u8]> for IoBox<Initialized>[src]

impl<I: Initialization> AsRef<[MaybeUninit<u8>]> for IoBox<I>[src]

impl AsRef<[u8]> for IoBox<Initialized>[src]

impl<I: Initialization> Borrow<[MaybeUninit<u8>]> for IoBox<I>[src]

impl Borrow<[u8]> for IoBox<Initialized>[src]

impl<I: Initialization> BorrowMut<[MaybeUninit<u8>]> for IoBox<I>[src]

impl BorrowMut<[u8]> for IoBox<Initialized>[src]

impl Debug for IoBox[src]

impl<I: Initialization> Deref for IoBox<I>[src]

type Target = [I::DerefTargetItem]

The resulting type after dereferencing.

impl<I: Initialization> DerefMut for IoBox<I>[src]

impl<I: Initialization> Drop for IoBox<I>[src]

impl Eq for IoBox<Initialized>[src]

impl<I: Initialization> From<Box<[<I as Initialization>::DerefTargetItem]>> for IoBox<I>[src]

impl From<Box<[u8]>> for IoBox<Uninitialized>[src]

impl<I: Initialization> From<IoBox<I>> for Box<[I::DerefTargetItem]>[src]

impl<I: Initialization> From<IoBox<I>> for Vec<I::DerefTargetItem>[src]

impl From<IoBox<Initialized>> for Box<[MaybeUninit<u8>]>[src]

impl From<IoBox<Initialized>> for Vec<MaybeUninit<u8>>[src]

impl<I: Initialization> From<Vec<<I as Initialization>::DerefTargetItem>> for IoBox<I>[src]

impl From<Vec<u8>> for IoBox<Uninitialized>[src]

impl PartialEq<[u8]> for IoBox<Initialized>[src]

impl PartialEq<IoBox<Initialized>> for IoBox<Initialized>[src]

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

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

impl<I: Initialization> SliceMut for IoBox<I>[src]

type Initialized = IoBox<Initialized>

The type that this turns into after initialization.

Auto Trait Implementations

impl<I> RefUnwindSafe for IoBox<I> where
    I: RefUnwindSafe

impl<I = Initialized> !Send for IoBox<I>

impl<I = Initialized> !Sync for IoBox<I>

impl<I> Unpin for IoBox<I> where
    I: Unpin

impl<I> UnwindSafe for IoBox<I> where
    I: UnwindSafe

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> SliceMutExt for T where
    T: SliceMut
[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.