Struct bytes_utils::SegmentedSlice [−][src]
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]
fn remaining(&self) -> usize[src]
fn chunk(&self) -> &[u8][src]
fn advance(&mut self, mut cnt: usize)[src]
fn copy_to_bytes(&mut self, len: usize) -> Bytes[src]
fn chunks_vectored<'s>(&'s self, dst: &mut [IoSlice<'s>]) -> usize[src]
pub fn has_remaining(&self) -> bool[src]
pub fn copy_to_slice(&mut self, dst: &mut [u8])[src]
pub fn get_u8(&mut self) -> u8[src]
pub fn get_i8(&mut self) -> i8[src]
pub fn get_u16(&mut self) -> u16[src]
pub fn get_u16_le(&mut self) -> u16[src]
pub fn get_i16(&mut self) -> i16[src]
pub fn get_i16_le(&mut self) -> i16[src]
pub fn get_u32(&mut self) -> u32[src]
pub fn get_u32_le(&mut self) -> u32[src]
pub fn get_i32(&mut self) -> i32[src]
pub fn get_i32_le(&mut self) -> i32[src]
pub fn get_u64(&mut self) -> u64[src]
pub fn get_u64_le(&mut self) -> u64[src]
pub fn get_i64(&mut self) -> i64[src]
pub fn get_i64_le(&mut self) -> i64[src]
pub fn get_u128(&mut self) -> u128[src]
pub fn get_u128_le(&mut self) -> u128[src]
pub fn get_i128(&mut self) -> i128[src]
pub fn get_i128_le(&mut self) -> i128[src]
pub fn get_uint(&mut self, nbytes: usize) -> u64[src]
pub fn get_uint_le(&mut self, nbytes: usize) -> u64[src]
pub fn get_int(&mut self, nbytes: usize) -> i64[src]
pub fn get_int_le(&mut self, nbytes: usize) -> i64[src]
pub fn get_f32(&mut self) -> f32[src]
pub fn get_f32_le(&mut self) -> f32[src]
pub fn get_f64(&mut self) -> f64[src]
pub fn get_f64_le(&mut self) -> f64[src]
pub fn take(self, limit: usize) -> Take<Self>[src]
pub fn chain<U>(self, next: U) -> Chain<Self, U> where
U: Buf, [src]
U: Buf,
pub fn reader(self) -> Reader<Self>[src]
impl<'a, B: Debug> Debug for SegmentedSlice<'a, B>[src]
impl<'a, B: Default> Default for SegmentedSlice<'a, B>[src]
fn default() -> SegmentedSlice<'a, B>[src]
Auto Trait Implementations
impl<'a, B> RefUnwindSafe for SegmentedSlice<'a, B> where
B: RefUnwindSafe, [src]
B: RefUnwindSafe,
impl<'a, B> Send for SegmentedSlice<'a, B> where
B: Send, [src]
B: Send,
impl<'a, B> Sync for SegmentedSlice<'a, B> where
B: Sync, [src]
B: Sync,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,