MCPcopy Create free account
hub / github.com/RustCrypto/formats / take

Method take

base64ct/src/decoder.rs:318–329  ·  view source on GitHub ↗

Take a specified number of bytes from the buffer. Returns as many bytes as possible, or an empty slice if the buffer has already been read to completion.

(&mut self, mut nbytes: usize)

Source from the content-addressed store, hash-verified

316 /// Returns as many bytes as possible, or an empty slice if the buffer has
317 /// already been read to completion.
318 fn take(&mut self, mut nbytes: usize) -> Result<&[u8], Error> {
319 debug_assert!(self.position <= self.length);
320 let start_pos = self.position;
321 let remaining_len = self.length.checked_sub(start_pos).ok_or(InvalidLength)?;
322
323 if nbytes > remaining_len {
324 nbytes = remaining_len;
325 }
326
327 self.position = self.position.checked_add(nbytes).ok_or(InvalidLength)?;
328 Ok(&self.decoded[start_pos..][..nbytes])
329 }
330
331 /// Have all of the bytes in this buffer been consumed?
332 fn is_empty(&self) -> bool {

Callers 5

parentMethod · 0.45
decodeMethod · 0.45
decode_to_endMethod · 0.45
fill_block_bufferMethod · 0.45
encode_to_vecMethod · 0.45

Calls 2

lenMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected