Struct bytes_utils::SegmentedSlice[][src]

pub struct SegmentedSlice<'a, B> { /* fields omitted */ }

A consumable view of a sequence of buffers.

This allows viewing a sequence of buffers as one buffer, without copying the bytes over. Unlike the SegmentedBuf, this doesn't allow for appending more buffers and doesn't drop the buffers as they are exhausted (though they all get exhausted, no leftovers are kept in them as the caller advances through it). On the other hand, it doesn't require an internal allocation in the form of VecDeque and can be based on any kind of slice.

Example

let mut buffers = [b"Hello" as &[_], b"", b" ", b"", b"World"];
let buf = SegmentedSlice::new(&mut buffers);

assert_eq!(11, buf.remaining());
assert_eq!(b"Hello", buf.chunk());

let mut out = String::new();
buf.reader().read_to_string(&mut out).expect("Doesn't cause IO errors");
assert_eq!("Hello World", out);

Optimizations

The copy_to_bytes method tries to avoid copies by delegating into the underlying buffer if possible (if the whole request can be fulfilled using only a single buffer). If that one is optimized (for example, the Bytes returns a shared instance instead of making a copy), the copying is avoided. If the request is across a buffer boundary, a copy is made.

The chunks_vectored will properly output as many slices as possible, not just 1 as the default implementation does.

Implementations

impl<'a, B: Buf> SegmentedSlice<'a, B>[src]

pub fn new(bufs: &'a mut [B]) -> Self[src]

Creates a new buffer out of a slice of buffers.

The buffers will then be taken in order to form one bigger buffer.

Each of the buffers in turn will be exhausted using its advance before proceeding to the next one. Note that the buffers are not dropped (unlike with SegmentedBuf).

Trait Implementations

impl<'a, B: Buf> Buf for SegmentedSlice<'a, B>[src]

impl<'a, B: Debug> Debug for SegmentedSlice<'a, B>[src]

impl<'a, B: Default> Default for SegmentedSlice<'a, B>[src]

Auto Trait Implementations

impl<'a, B> RefUnwindSafe for SegmentedSlice<'a, B> where
    B: RefUnwindSafe
[src]

impl<'a, B> Send for SegmentedSlice<'a, B> where
    B: Send
[src]

impl<'a, B> Sync for SegmentedSlice<'a, B> where
    B: Sync
[src]

impl<'a, B> Unpin for SegmentedSlice<'a, B>[src]

impl<'a, B> !UnwindSafe for SegmentedSlice<'a, B>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.