pub trait BufferView<B: SplitByteSlice>: Sized + AsRef<[u8]> {
Show 15 methods
// Required methods
fn take_front(&mut self, n: usize) -> Option<B>;
fn take_back(&mut self, n: usize) -> Option<B>;
fn into_rest(self) -> B;
// Provided methods
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn take_rest_front(&mut self) -> B { ... }
fn take_rest_back(&mut self) -> B { ... }
fn take_byte_front(&mut self) -> Option<u8> { ... }
fn take_byte_back(&mut self) -> Option<u8> { ... }
fn peek_obj_front<T>(&self) -> Option<&T>
where T: FromBytes + KnownLayout + Immutable + Unaligned { ... }
fn take_obj_front<T>(&mut self) -> Option<Ref<B, T>>
where T: KnownLayout + Immutable + Unaligned { ... }
fn take_slice_front<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
where T: Immutable + Unaligned { ... }
fn peek_obj_back<T>(&mut self) -> Option<&T>
where T: FromBytes + KnownLayout + Immutable + Unaligned { ... }
fn take_obj_back<T>(&mut self) -> Option<Ref<B, T>>
where T: Immutable + KnownLayout + Unaligned { ... }
fn take_slice_back<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
where T: Immutable + Unaligned { ... }
}Expand description
A view into a ShrinkBuffer.
A BufferView borrows a ShrinkBuffer, and provides methods to consume
bytes from the buffer’s body. It is primarily intended to be used for
parsing, although it provides methods which are useful for serialization as
well.
A BufferView only provides immutable access to the contents of the buffer.
For mutable access, see BufferViewMut.
§Notable implementations
BufferView is implemented for mutable references to byte slices (&mut &[u8] and &mut &mut [u8]).
Required Methods§
Sourcefn take_front(&mut self, n: usize) -> Option<B>
fn take_front(&mut self, n: usize) -> Option<B>
Takes n bytes from the front of the buffer’s body.
take_front consumes n bytes from the front of the buffer’s body.
After a successful call to take_front(n), the body is n bytes
shorter and, if Self: GrowBuffer, the prefix is n bytes longer. If
the body is not at least n bytes in length, take_front returns
None.
Sourcefn take_back(&mut self, n: usize) -> Option<B>
fn take_back(&mut self, n: usize) -> Option<B>
Takes n bytes from the back of the buffer’s body.
take_back consumes n bytes from the back of the buffer’s body. After
a successful call to take_back(n), the body is n bytes shorter and,
if Self: GrowBuffer, the suffix is n bytes longer. If the body is
not at least n bytes in length, take_back returns None.
Provided Methods§
Sourcefn take_rest_front(&mut self) -> B
fn take_rest_front(&mut self) -> B
Takes the rest of the buffer’s body from the front.
take_rest_front consumes the rest of the bytes from the buffer’s body.
After a call to take_rest_front, the body is empty and, if Self: GrowBuffer, the bytes which were previously in the body are now in the
prefix.
Sourcefn take_rest_back(&mut self) -> B
fn take_rest_back(&mut self) -> B
Takes the rest of the buffer’s body from the back.
take_rest_back consumes the rest of the bytes from the buffer’s body.
After a call to take_rest_back, the body is empty and, if Self: GrowBuffer, the bytes which were previously in the body are now in the
suffix.
Sourcefn take_byte_front(&mut self) -> Option<u8>
fn take_byte_front(&mut self) -> Option<u8>
Takes a single byte of the buffer’s body from the front.
take_byte_front consumes a single byte from the from of the buffer’s
body. It’s equivalent to calling take_front(1) and copying out the
single byte on successful return.
Sourcefn take_byte_back(&mut self) -> Option<u8>
fn take_byte_back(&mut self) -> Option<u8>
Takes a single byte of the buffer’s body from the back.
take_byte_back consumes a single byte from the fron of the buffer’s
body. It’s equivalent to calling take_back(1) and copying out the
single byte on successful return.
Sourcefn peek_obj_front<T>(&self) -> Option<&T>
fn peek_obj_front<T>(&self) -> Option<&T>
Peeks at an object at the front of the buffer’s body.
peek_obj_front peeks at size_of::<T>() bytes at the front of the
buffer’s body, and interprets them as a T. Unlike take_obj_front,
peek_obj_front does not modify the body. If the body is not at least
size_of::<T>() bytes in length, peek_obj_front returns None.
Sourcefn take_obj_front<T>(&mut self) -> Option<Ref<B, T>>
fn take_obj_front<T>(&mut self) -> Option<Ref<B, T>>
Takes an object from the front of the buffer’s body.
take_obj_front consumes size_of::<T>() bytes from the front of the
buffer’s body, and interprets them as a T. After a successful call to
take_obj_front::<T>(), the body is size_of::<T>() bytes shorter and,
if Self: GrowBuffer, the prefix is size_of::<T>() bytes longer. If
the body is not at least size_of::<T>() bytes in length,
take_obj_front returns None.
Sourcefn take_slice_front<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
fn take_slice_front<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
Takes a slice of objects from the front of the buffer’s body.
take_slice_front consumes n * size_of::<T>() bytes from the front of
the buffer’s body, and interprets them as a [T] with n elements.
After a successful call to take_slice_front::<T>(), the body is n * size_of::<T>() bytes shorter and, if Self: GrowBuffer, the prefix is
n * size_of::<T>() bytes longer. If the body is not at least n * size_of::<T>() bytes in length, take_slice_front returns None.
§Panics
Panics if T is a zero-sized type.
Sourcefn peek_obj_back<T>(&mut self) -> Option<&T>
fn peek_obj_back<T>(&mut self) -> Option<&T>
Peeks at an object at the back of the buffer’s body.
peek_obj_back peeks at size_of::<T>() bytes at the back of the
buffer’s body, and interprets them as a T. Unlike take_obj_back,
peek_obj_back does not modify the body. If the body is not at least
size_of::<T>() bytes in length, peek_obj_back returns None.
Sourcefn take_obj_back<T>(&mut self) -> Option<Ref<B, T>>
fn take_obj_back<T>(&mut self) -> Option<Ref<B, T>>
Takes an object from the back of the buffer’s body.
take_obj_back consumes size_of::<T>() bytes from the back of the
buffer’s body, and interprets them as a T. After a successful call to
take_obj_back::<T>(), the body is size_of::<T>() bytes shorter and,
if Self: GrowBuffer, the suffix is size_of::<T>() bytes longer. If
the body is not at least size_of::<T>() bytes in length,
take_obj_back returns None.
Sourcefn take_slice_back<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
fn take_slice_back<T>(&mut self, n: usize) -> Option<Ref<B, [T]>>
Takes a slice of objects from the back of the buffer’s body.
take_slice_back consumes n * size_of::<T>() bytes from the back of
the buffer’s body, and interprets them as a [T] with n elements.
After a successful call to take_slice_back::<T>(), the body is n * size_of::<T>() bytes shorter and, if Self: GrowBuffer, the suffix is
n * size_of::<T>() bytes longer. If the body is not at least n * size_of::<T>() bytes in length, take_slice_back returns None.
§Panics
Panics if T is a zero-sized type.
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.