Trait IoVectoredBuf
pub trait IoVectoredBuf: 'static {
// Required method
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>;
// Provided methods
fn total_len(&self) -> usize { ... }
fn owned_iter(self) -> Result<VectoredBufIter<Self>, Self>
where Self: Sized { ... }
fn slice(self, begin: usize) -> VectoredSlice<Self>
where Self: Sized { ... }
}Expand description
A trait for vectored buffers.
§Note for implementors
The iterator must be idemptotent and always yield the same slices in the
exact same orders, i.e., Iterator::enumerate will mark the same buffer
with same index.
Required Methods§
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
An iterator of initialized slice of the buffers.
Provided Methods§
fn owned_iter(self) -> Result<VectoredBufIter<Self>, Self>where
Self: Sized,
fn owned_iter(self) -> Result<VectoredBufIter<Self>, Self>where
Self: Sized,
Wrap self into an owned iterator.
fn slice(self, begin: usize) -> VectoredSlice<Self>where
Self: Sized,
fn slice(self, begin: usize) -> VectoredSlice<Self>where
Self: Sized,
Get an owned view of the vectored buffer that skips the first
begin-many initialized bytes.
§Examples
use compio_buf::{IoBuf, IoVectoredBuf, VectoredSlice};
/// Create a buffer with given content and capacity.
fn new_buf(slice: &[u8], cap: usize) -> Vec<u8> {
let mut buf = Vec::new();
buf.reserve_exact(cap);
buf.extend_from_slice(slice);
buf
}
let bufs = [new_buf(b"hello", 10), new_buf(b"world", 10)];
let vectored_buf = bufs.slice(3);
let mut iter = vectored_buf.iter_slice();
let buf1 = iter.next().unwrap();
let buf2 = iter.next().unwrap();
assert_eq!(&buf1.as_init()[..], b"lo");
assert_eq!(&buf2.as_init()[..], b"world");
let bufs = [new_buf(b"hello", 10), new_buf(b"world", 10)];
let vectored_buf = bufs.slice(6);
let mut iter = vectored_buf.iter_slice();
let buf1 = iter.next().unwrap();
assert!(iter.next().is_none());
assert_eq!(&buf1.as_init()[..], b"orld");Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
§impl IoVectoredBuf for ()
impl IoVectoredBuf for ()
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T> IoVectoredBuf for &'static [T]where
T: IoBuf,
impl<T> IoVectoredBuf for &'static [T]where
T: IoBuf,
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T> IoVectoredBuf for &'static mut [T]where
T: IoBuf,
impl<T> IoVectoredBuf for &'static mut [T]where
T: IoBuf,
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T> IoVectoredBuf for (T,)where
T: IoBuf,
impl<T> IoVectoredBuf for (T,)where
T: IoBuf,
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T, Rest> IoVectoredBuf for (T, Rest)where
T: IoBuf,
Rest: IoVectoredBuf,
impl<T, Rest> IoVectoredBuf for (T, Rest)where
T: IoBuf,
Rest: IoVectoredBuf,
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T, const N: usize> IoVectoredBuf for [T; N]where
T: IoBuf,
impl<T, const N: usize> IoVectoredBuf for [T; N]where
T: IoBuf,
fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
§impl<T, const N: usize> IoVectoredBuf for SmallVec<[T; N]>
Available on crate feature smallvec only.
impl<T, const N: usize> IoVectoredBuf for SmallVec<[T; N]>
Available on crate feature
smallvec only.fn iter_slice(&self) -> impl Iterator<Item = &[u8]>
Implementors§
impl<T> IoVectoredBuf for VectoredSlice<T>where
T: IoVectoredBuf,
impl<T, A> IoVectoredBuf for Vec<T, A>
impl<T, const N: usize> IoVectoredBuf for ArrayVec<T, N>where
T: IoBuf,
Available on crate feature
arrayvec only.