[−][src]Struct ioslice::IoBox
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]
these: &mut [Self]
) -> &mut [IoSliceMut<'_, I>]
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]
length: usize
) -> Result<IoBox<Uninitialized>, AllocationError>
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]
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]
fn borrow_mut(&mut self) -> &mut [MaybeUninit<u8>]
[src]
impl BorrowMut<[u8]> for IoBox<Initialized>
[src]
fn borrow_mut(&mut self) -> &mut [u8]
[src]
impl Debug for IoBox
[src]
impl<I: Initialization> Deref for IoBox<I>
[src]
type Target = [I::DerefTargetItem]
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
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]
fn from(io_box: IoBox<Initialized>) -> Self
[src]
impl From<IoBox<Initialized>> for Vec<MaybeUninit<u8>>
[src]
fn from(io_box: IoBox<Initialized>) -> Self
[src]
impl<I: Initialization> From<Vec<<I as Initialization>::DerefTargetItem>> for IoBox<I>
[src]
fn from(vector: Vec<I::DerefTargetItem>) -> Self
[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]
fn eq(&self, other: &IoSlice<'_, Initialized>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<IoSliceMut<'a, Initialized>> for IoBox<Initialized>
[src]
fn eq(&self, other: &IoSliceMut<'_, Initialized>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<I: Initialization> SliceMut for IoBox<I>
[src]
type Initialized = IoBox<Initialized>
The type that this turns into after initialization.
fn as_maybe_uninit_slice(&self) -> &[MaybeUninit<u8>]
[src]
fn as_maybe_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]
[src]
unsafe fn assume_init(self) -> Self::Initialized
[src]
Auto Trait Implementations
impl<I> RefUnwindSafe for IoBox<I> where
I: RefUnwindSafe,
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,
I: Unpin,
impl<I> UnwindSafe for IoBox<I> where
I: UnwindSafe,
I: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SliceMutExt for T where
T: SliceMut,
[src]
T: SliceMut,
fn init_by_filling(self, byte: u8) -> Self::Initialized
[src]
fn init_by_zeroing(self) -> Self::Initialized
[src]
fn init_by_copying(self, source: &[u8]) -> Self::Initialized
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,