Struct IoSlice

struct IoSlice<'a>(_)

A buffer type used with Write::write_vectored.

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

Implementations

impl<'a> IoSlice<'a>

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

Creates a new IoSlice 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 IoSlice::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::IoSlice;
use std::ops::Deref;

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

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

Advance a slice of slices.

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

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

Panics

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

Examples

use std::io::IoSlice;
use std::ops::Deref;

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

// Mark 10 bytes as written.
IoSlice::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 as_slice(self: Self) -> &'a [u8]

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

This doesn't borrow from self, so is less restrictive than calling .deref(), which does.

Examples

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

let data = b"abcdef";

let mut io_slice = IoSlice::new(data);
let tail = &io_slice.as_slice()[3..];

// This works because `tail` doesn't borrow `io_slice`
io_slice = IoSlice::new(tail);

assert_eq!(io_slice.as_slice(), b"def");

impl<'a> Clone for IoSlice<'a>

fn clone(self: &Self) -> IoSlice<'a>

impl<'a> Copy for IoSlice<'a>

impl<'a> Debug for IoSlice<'a>

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

impl<'a> Deref for IoSlice<'a>

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

impl<'a> Freeze for IoSlice<'a>

impl<'a> RefUnwindSafe for IoSlice<'a>

impl<'a> Send for IoSlice<'a>

impl<'a> Sync for IoSlice<'a>

impl<'a> Unpin for IoSlice<'a>

impl<'a> UnwindSafe for IoSlice<'a>

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

impl<T> Any for IoSlice<'a>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for IoSlice<'a>

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

impl<T> BorrowMut for IoSlice<'a>

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

impl<T> CloneToUninit for IoSlice<'a>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for IoSlice<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for IoSlice<'a>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for IoSlice<'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 IoSlice<'a>

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

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

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