Struct IoSliceMut

#[repr(transparent)]
pub struct IoSliceMut<'a>(pub(in ::io::io_slice) 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.

Fields

0: IoSliceMut<'a>

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(&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) -> &'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");

Trait Implementations

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

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

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

type Target = [u8];
fn deref(&self) -> &[u8]

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

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

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

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

Auto Trait Implementations

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

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

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

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

impl<'a> UnsafeUnpin for IoSliceMut<'a>

Blanket Implementations

impl<P, T> Receiver for IoSliceMut<'a> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

impl<T> Any for IoSliceMut<'a> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for IoSliceMut<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for IoSliceMut<'a> where T: ?Sized,

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

impl<T> From<T> for IoSliceMut<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for IoSliceMut<'a> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for IoSliceMut<'a>

impl<T, U> Into<U> for IoSliceMut<'a> where U: From<T>,

fn into(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<U> for IoSliceMut<'a> where U: Into<T>,

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

impl<T, U> TryInto<U> for IoSliceMut<'a> where U: TryFrom<T>,

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