Struct IoSliceMut

struct IoSliceMut<'a>(_)

A buffer type used with Read::read_vectored.

It is semantically a wrapper around a &mut [u8], but is guaranteed to be ABI compatible with the iovec type on Unix platforms and WSABUF on Windows.

Implementations

impl<'a> IoSliceMut<'a>

fn new(buf: &'a mut [u8]) -> IoSliceMut<'a>

Creates a new IoSliceMut wrapping a byte slice.

Panics

Panics on Windows if the slice is larger than 4GB.

fn advance(self: &mut Self, n: usize)

Advance the internal cursor of the slice.

Also see IoSliceMut::advance_slices to advance the cursors of multiple buffers.

Panics

Panics when trying to advance beyond the end of the slice.

Examples

use std::io::IoSliceMut;
use std::ops::Deref;

let mut data = [1; 8];
let mut buf = IoSliceMut::new(&mut data);

// Mark 3 bytes as read.
buf.advance(3);
assert_eq!(buf.deref(), [1; 5].as_ref());
fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize)

Advance a slice of slices.

Shrinks the slice to remove any IoSliceMuts that are fully advanced over. If the cursor ends up in the middle of an IoSliceMut, it is modified to start at that cursor.

For example, if we have a slice of two 8-byte IoSliceMuts, and we advance by 10 bytes, the result will only include the second IoSliceMut, advanced by 2 bytes.

Panics

Panics when trying to advance beyond the end of the slices.

Examples

use std::io::IoSliceMut;
use std::ops::Deref;

let mut buf1 = [1; 8];
let mut buf2 = [2; 16];
let mut buf3 = [3; 8];
let mut bufs = &mut [
    IoSliceMut::new(&mut buf1),
    IoSliceMut::new(&mut buf2),
    IoSliceMut::new(&mut buf3),
][..];

// Mark 10 bytes as read.
IoSliceMut::advance_slices(&mut bufs, 10);
assert_eq!(bufs[0].deref(), [2; 14].as_ref());
assert_eq!(bufs[1].deref(), [3; 8].as_ref());
const fn into_slice(self: Self) -> &'a mut [u8]

Get the underlying bytes as a mutable slice with the original lifetime.

Examples

#![feature(io_slice_as_bytes)]
use std::io::IoSliceMut;

let mut data = *b"abcdef";
let io_slice = IoSliceMut::new(&mut data);
io_slice.into_slice()[0] = b'A';

assert_eq!(&data, b"Abcdef");

impl<'a> Debug for IoSliceMut<'a>

fn fmt(self: &Self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result

impl<'a> Deref for IoSliceMut<'a>

fn deref(self: &Self) -> &[u8]

impl<'a> DerefMut for IoSliceMut<'a>

fn deref_mut(self: &mut Self) -> &mut [u8]

impl<'a> Freeze for IoSliceMut<'a>

impl<'a> RefUnwindSafe for IoSliceMut<'a>

impl<'a> Send for IoSliceMut<'a>

impl<'a> Sync for IoSliceMut<'a>

impl<'a> Unpin for IoSliceMut<'a>

impl<'a> UnwindSafe for IoSliceMut<'a>

impl<P, T> Receiver for IoSliceMut<'a>

impl<T> Any for IoSliceMut<'a>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for IoSliceMut<'a>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for IoSliceMut<'a>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for IoSliceMut<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for IoSliceMut<'a>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for IoSliceMut<'a>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for IoSliceMut<'a>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>