Trait nuts_bytes::TakeBytes
source · pub trait TakeBytes<'tb> {
// Required method
fn take_bytes(&mut self, n: usize) -> Result<Cow<'tb, [u8]>>;
// Provided method
fn take_bytes_to(&mut self, buf: &mut [u8]) -> Result<()> { ... }
}
Expand description
Trait that describes a reader of binary data.
The Reader
utility accepts all types that implements this trait.
Required Methods§
sourcefn take_bytes(&mut self, n: usize) -> Result<Cow<'tb, [u8]>>
fn take_bytes(&mut self, n: usize) -> Result<Cow<'tb, [u8]>>
Reads n
bytes from the source.
If possible a slice of borrowed data of the given size (n
) wrapped
into Cow::Borrowed
should be returned.
If the data cannot be borrowed a Vec<u8>
wrapped into a
Cow::Owned
should be returned.
Errors
If not enough data are available an Error::Eof
error is returned.
Provided Methods§
sourcefn take_bytes_to(&mut self, buf: &mut [u8]) -> Result<()>
fn take_bytes_to(&mut self, buf: &mut [u8]) -> Result<()>
Reads some bytes from the source and puts them into the given buffer
buf
.
Errors
If not enough data are available to fill buf
an Error::Eof
error
is returned.
Implementations on Foreign Types§
source§impl<'tb> TakeBytes<'tb> for &'tb [u8]
impl<'tb> TakeBytes<'tb> for &'tb [u8]
TakeBytes
is implemented for &[u8]
by taking the first part of the
slice.
Note that taking bytes updates the slice to point to the yet unread part. The slice will be empty when EOF is reached.