pub struct Cursor<B: Buf> { /* private fields */ }Expand description
A stateful wrapper for sequential reading and writing in a buffer.
The Cursor keeps track of the current position within the underlying buffer B,
ensuring that all read and write operations automatically advance the position
and respect the buffer’s boundaries.
Implementations§
Source§impl<B: Buf> Cursor<B>
impl<B: Buf> Cursor<B>
Sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Returns the number of bytes remaining until the end of the buffer.
Sourcepub fn advance(&mut self, amount: usize) -> BufResult<()>
pub fn advance(&mut self, amount: usize) -> BufResult<()>
Advances the cursor position by amount bytes.
§Errors
Returns BufError::UnexpectedEof if amount exceeds the remaining bytes.
Sourcepub fn rewind(&mut self, amount: usize) -> BufResult<()>
pub fn rewind(&mut self, amount: usize) -> BufResult<()>
Moves the cursor position backward by amount bytes.
§Errors
Returns BufError::OutOfBounds if amount exceeds the current position.
Sourcepub fn seek_to(&mut self, position: usize) -> BufResult<()>
pub fn seek_to(&mut self, position: usize) -> BufResult<()>
Sets the cursor position to an absolute position.
§Errors
Returns BufError::OutOfBounds if position exceeds the buffer’s length.
Sourcepub fn seek_from_end(&mut self, offset_from_end: usize) -> BufResult<()>
pub fn seek_from_end(&mut self, offset_from_end: usize) -> BufResult<()>
Sets the cursor position relative to the end of the buffer.
§Errors
Returns BufError::OutOfBounds if offset_from_end exceeds the buffer’
Sourcepub fn peek_u8(&self) -> BufResult<u8>
pub fn peek_u8(&self) -> BufResult<u8>
Peeks at a single byte at the current position without advancing the cursor.
Sourcepub fn peek_u16_be(&self) -> BufResult<u16>
pub fn peek_u16_be(&self) -> BufResult<u16>
Peeks at a 16-bit big-endian integer at the current position without advancing.
Sourcepub fn peek_u32_be(&self) -> BufResult<u32>
pub fn peek_u32_be(&self) -> BufResult<u32>
Peeks at a 32-bit big-endian integer at the current position without advancing.
Sourcepub fn peek_array<const N: usize>(&self) -> BufResult<[u8; N]>
pub fn peek_array<const N: usize>(&self) -> BufResult<[u8; N]>
Peeks at a fixed-size byte array at the current position without advancing.
Sourcepub fn read_u16_be(&mut self) -> BufResult<u16>
pub fn read_u16_be(&mut self) -> BufResult<u16>
Reads a 16-bit big-endian integer and advances the cursor by 2.
Sourcepub fn read_u32_be(&mut self) -> BufResult<u32>
pub fn read_u32_be(&mut self) -> BufResult<u32>
Reads a 32-bit big-endian integer and advances the cursor by 4.
Source§impl<B: BufMut> Cursor<B>
impl<B: BufMut> Cursor<B>
Sourcepub fn poke_u8(&mut self, val: u8) -> BufResult<()>
pub fn poke_u8(&mut self, val: u8) -> BufResult<()>
Writes a single byte at the current position without advancing the cursor.
Sourcepub fn poke_u16_be(&mut self, val: u16) -> BufResult<()>
pub fn poke_u16_be(&mut self, val: u16) -> BufResult<()>
Writes a 16-bit big-endian integer at the current position without advancing.
Sourcepub fn poke_u32_be(&mut self, val: u32) -> BufResult<()>
pub fn poke_u32_be(&mut self, val: u32) -> BufResult<()>
Writes a 32-bit big-endian integer at the current position without advancing.
Sourcepub fn poke_array<const N: usize>(&mut self, val: &[u8; N]) -> BufResult<()>
pub fn poke_array<const N: usize>(&mut self, val: &[u8; N]) -> BufResult<()>
Writes a fixed-size byte array at the current position without advancing.
Sourcepub fn poke_slice(&mut self, src: &[u8]) -> BufResult<()>
pub fn poke_slice(&mut self, src: &[u8]) -> BufResult<()>
Writes a byte slice at the current position without advancing the cursor.
Sourcepub fn write_u8(&mut self, val: u8) -> BufResult<()>
pub fn write_u8(&mut self, val: u8) -> BufResult<()>
Writes a single byte and advances the cursor by 1.
Sourcepub fn write_u16_be(&mut self, val: u16) -> BufResult<()>
pub fn write_u16_be(&mut self, val: u16) -> BufResult<()>
Writes a 16-bit big-endian integer and advances the cursor by 2.
Sourcepub fn write_u32_be(&mut self, val: u32) -> BufResult<()>
pub fn write_u32_be(&mut self, val: u32) -> BufResult<()>
Writes a 32-bit big-endian integer and advances the cursor by 4.
Sourcepub fn write_array<const N: usize>(&mut self, val: &[u8; N]) -> BufResult<()>
pub fn write_array<const N: usize>(&mut self, val: &[u8; N]) -> BufResult<()>
Writes a fixed-size byte array and advances the cursor by N.
Sourcepub fn write_slice(&mut self, src: &[u8]) -> BufResult<()>
pub fn write_slice(&mut self, src: &[u8]) -> BufResult<()>
Writes a byte slice and advances the cursor by the slice’s length.
§Errors
Returns BufError::OutOfBounds or BufError::UnexpectedEof depending
on the underlying BufMut implementation if the slice exceeds buffer capacity.