pub trait Buf {
Show 215 methods
// Required methods
fn remaining(&self) -> usize;
fn buffer(&self) -> &[u8] ⓘ;
fn advance(&mut self, cnt: usize);
fn segment(&self, range: impl RangeBounds<usize>) -> Self
where Self: Sized;
fn truncate(&mut self, len: usize);
fn split_off(&mut self, at: usize) -> Self
where Self: Sized;
fn split_to(&mut self, at: usize) -> Self
where Self: Sized;
// Provided methods
fn buffer_from(&self, offset: usize) -> &[u8] ⓘ { ... }
fn buffer_from_checked(&self, offset: usize) -> Option<&[u8]> { ... }
fn prefix(&self, len: usize) -> &[u8] ⓘ { ... }
fn prefix_checked(&self, len: usize) -> Option<&[u8]> { ... }
fn suffix(&self, len: usize) -> &[u8] ⓘ { ... }
fn suffix_checked(&self, len: usize) -> Option<&[u8]> { ... }
fn split_off_checked(&mut self, at: usize) -> Option<Self>
where Self: Sized { ... }
fn try_split_off(&mut self, at: usize) -> Result<Self, OutOfBounds>
where Self: Sized { ... }
fn split_to_checked(&mut self, at: usize) -> Option<Self>
where Self: Sized { ... }
fn try_split_to(&mut self, at: usize) -> Result<Self, OutOfBounds>
where Self: Sized { ... }
fn has_remaining(&self) -> bool { ... }
fn try_advance(&mut self, cnt: usize) -> Result<(), TryAdvanceError> { ... }
fn try_segment(
&self,
range: impl RangeBounds<usize>,
) -> Result<Self, TrySegmentError>
where Self: Sized { ... }
fn peek_u16_le(&self) -> u16 { ... }
fn peek_u16_le_checked(&self) -> Option<u16> { ... }
fn try_peek_u16_le(&self) -> Result<u16, TryPeekError> { ... }
fn peek_u16_be(&self) -> u16 { ... }
fn peek_u16_be_checked(&self) -> Option<u16> { ... }
fn try_peek_u16_be(&self) -> Result<u16, TryPeekError> { ... }
fn peek_u16_ne(&self) -> u16 { ... }
fn peek_u16_ne_checked(&self) -> Option<u16> { ... }
fn try_peek_u16_ne(&self) -> Result<u16, TryPeekError> { ... }
fn peek_u32_le(&self) -> u32 { ... }
fn peek_u32_le_checked(&self) -> Option<u32> { ... }
fn try_peek_u32_le(&self) -> Result<u32, TryPeekError> { ... }
fn peek_u32_be(&self) -> u32 { ... }
fn peek_u32_be_checked(&self) -> Option<u32> { ... }
fn try_peek_u32_be(&self) -> Result<u32, TryPeekError> { ... }
fn peek_u32_ne(&self) -> u32 { ... }
fn peek_u32_ne_checked(&self) -> Option<u32> { ... }
fn try_peek_u32_ne(&self) -> Result<u32, TryPeekError> { ... }
fn peek_u64_le(&self) -> u64 { ... }
fn peek_u64_le_checked(&self) -> Option<u64> { ... }
fn try_peek_u64_le(&self) -> Result<u64, TryPeekError> { ... }
fn peek_u64_be(&self) -> u64 { ... }
fn peek_u64_be_checked(&self) -> Option<u64> { ... }
fn try_peek_u64_be(&self) -> Result<u64, TryPeekError> { ... }
fn peek_u64_ne(&self) -> u64 { ... }
fn peek_u64_ne_checked(&self) -> Option<u64> { ... }
fn try_peek_u64_ne(&self) -> Result<u64, TryPeekError> { ... }
fn peek_u128_le(&self) -> u128 { ... }
fn peek_u128_le_checked(&self) -> Option<u128> { ... }
fn try_peek_u128_le(&self) -> Result<u128, TryPeekError> { ... }
fn peek_u128_be(&self) -> u128 { ... }
fn peek_u128_be_checked(&self) -> Option<u128> { ... }
fn try_peek_u128_be(&self) -> Result<u128, TryPeekError> { ... }
fn peek_u128_ne(&self) -> u128 { ... }
fn peek_u128_ne_checked(&self) -> Option<u128> { ... }
fn try_peek_u128_ne(&self) -> Result<u128, TryPeekError> { ... }
fn peek_i16_le(&self) -> i16 { ... }
fn peek_i16_le_checked(&self) -> Option<i16> { ... }
fn try_peek_i16_le(&self) -> Result<i16, TryPeekError> { ... }
fn peek_i16_be(&self) -> i16 { ... }
fn peek_i16_be_checked(&self) -> Option<i16> { ... }
fn try_peek_i16_be(&self) -> Result<i16, TryPeekError> { ... }
fn peek_i16_ne(&self) -> i16 { ... }
fn peek_i16_ne_checked(&self) -> Option<i16> { ... }
fn try_peek_i16_ne(&self) -> Result<i16, TryPeekError> { ... }
fn peek_i32_le(&self) -> i32 { ... }
fn peek_i32_le_checked(&self) -> Option<i32> { ... }
fn try_peek_i32_le(&self) -> Result<i32, TryPeekError> { ... }
fn peek_i32_be(&self) -> i32 { ... }
fn peek_i32_be_checked(&self) -> Option<i32> { ... }
fn try_peek_i32_be(&self) -> Result<i32, TryPeekError> { ... }
fn peek_i32_ne(&self) -> i32 { ... }
fn peek_i32_ne_checked(&self) -> Option<i32> { ... }
fn try_peek_i32_ne(&self) -> Result<i32, TryPeekError> { ... }
fn peek_i64_le(&self) -> i64 { ... }
fn peek_i64_le_checked(&self) -> Option<i64> { ... }
fn try_peek_i64_le(&self) -> Result<i64, TryPeekError> { ... }
fn peek_i64_be(&self) -> i64 { ... }
fn peek_i64_be_checked(&self) -> Option<i64> { ... }
fn try_peek_i64_be(&self) -> Result<i64, TryPeekError> { ... }
fn peek_i64_ne(&self) -> i64 { ... }
fn peek_i64_ne_checked(&self) -> Option<i64> { ... }
fn try_peek_i64_ne(&self) -> Result<i64, TryPeekError> { ... }
fn peek_i128_le(&self) -> i128 { ... }
fn peek_i128_le_checked(&self) -> Option<i128> { ... }
fn try_peek_i128_le(&self) -> Result<i128, TryPeekError> { ... }
fn peek_i128_be(&self) -> i128 { ... }
fn peek_i128_be_checked(&self) -> Option<i128> { ... }
fn try_peek_i128_be(&self) -> Result<i128, TryPeekError> { ... }
fn peek_i128_ne(&self) -> i128 { ... }
fn peek_i128_ne_checked(&self) -> Option<i128> { ... }
fn try_peek_i128_ne(&self) -> Result<i128, TryPeekError> { ... }
fn peek_f32_le(&self) -> f32 { ... }
fn peek_f32_le_checked(&self) -> Option<f32> { ... }
fn try_peek_f32_le(&self) -> Result<f32, TryPeekError> { ... }
fn peek_f32_be(&self) -> f32 { ... }
fn peek_f32_be_checked(&self) -> Option<f32> { ... }
fn try_peek_f32_be(&self) -> Result<f32, TryPeekError> { ... }
fn peek_f32_ne(&self) -> f32 { ... }
fn peek_f32_ne_checked(&self) -> Option<f32> { ... }
fn try_peek_f32_ne(&self) -> Result<f32, TryPeekError> { ... }
fn peek_f64_le(&self) -> f64 { ... }
fn peek_f64_le_checked(&self) -> Option<f64> { ... }
fn try_peek_f64_le(&self) -> Result<f64, TryPeekError> { ... }
fn peek_f64_be(&self) -> f64 { ... }
fn peek_f64_be_checked(&self) -> Option<f64> { ... }
fn try_peek_f64_be(&self) -> Result<f64, TryPeekError> { ... }
fn peek_f64_ne(&self) -> f64 { ... }
fn peek_f64_ne_checked(&self) -> Option<f64> { ... }
fn try_peek_f64_ne(&self) -> Result<f64, TryPeekError> { ... }
fn read_u16_le(&mut self) -> u16 { ... }
fn read_u16_le_checked(&mut self) -> Option<u16> { ... }
fn try_read_u16_le(&mut self) -> Result<u16, TryReadError> { ... }
fn read_u16_be(&mut self) -> u16 { ... }
fn read_u16_be_checked(&mut self) -> Option<u16> { ... }
fn try_read_u16_be(&mut self) -> Result<u16, TryReadError> { ... }
fn read_u16_ne(&mut self) -> u16 { ... }
fn read_u16_ne_checked(&mut self) -> Option<u16> { ... }
fn try_read_u16_ne(&mut self) -> Result<u16, TryReadError> { ... }
fn read_u32_le(&mut self) -> u32 { ... }
fn read_u32_le_checked(&mut self) -> Option<u32> { ... }
fn try_read_u32_le(&mut self) -> Result<u32, TryReadError> { ... }
fn read_u32_be(&mut self) -> u32 { ... }
fn read_u32_be_checked(&mut self) -> Option<u32> { ... }
fn try_read_u32_be(&mut self) -> Result<u32, TryReadError> { ... }
fn read_u32_ne(&mut self) -> u32 { ... }
fn read_u32_ne_checked(&mut self) -> Option<u32> { ... }
fn try_read_u32_ne(&mut self) -> Result<u32, TryReadError> { ... }
fn read_u64_le(&mut self) -> u64 { ... }
fn read_u64_le_checked(&mut self) -> Option<u64> { ... }
fn try_read_u64_le(&mut self) -> Result<u64, TryReadError> { ... }
fn read_u64_be(&mut self) -> u64 { ... }
fn read_u64_be_checked(&mut self) -> Option<u64> { ... }
fn try_read_u64_be(&mut self) -> Result<u64, TryReadError> { ... }
fn read_u64_ne(&mut self) -> u64 { ... }
fn read_u64_ne_checked(&mut self) -> Option<u64> { ... }
fn try_read_u64_ne(&mut self) -> Result<u64, TryReadError> { ... }
fn read_u128_le(&mut self) -> u128 { ... }
fn read_u128_le_checked(&mut self) -> Option<u128> { ... }
fn try_read_u128_le(&mut self) -> Result<u128, TryReadError> { ... }
fn read_u128_be(&mut self) -> u128 { ... }
fn read_u128_be_checked(&mut self) -> Option<u128> { ... }
fn try_read_u128_be(&mut self) -> Result<u128, TryReadError> { ... }
fn read_u128_ne(&mut self) -> u128 { ... }
fn read_u128_ne_checked(&mut self) -> Option<u128> { ... }
fn try_read_u128_ne(&mut self) -> Result<u128, TryReadError> { ... }
fn read_i16_le(&mut self) -> i16 { ... }
fn read_i16_le_checked(&mut self) -> Option<i16> { ... }
fn try_read_i16_le(&mut self) -> Result<i16, TryReadError> { ... }
fn read_i16_be(&mut self) -> i16 { ... }
fn read_i16_be_checked(&mut self) -> Option<i16> { ... }
fn try_read_i16_be(&mut self) -> Result<i16, TryReadError> { ... }
fn read_i16_ne(&mut self) -> i16 { ... }
fn read_i16_ne_checked(&mut self) -> Option<i16> { ... }
fn try_read_i16_ne(&mut self) -> Result<i16, TryReadError> { ... }
fn read_i32_le(&mut self) -> i32 { ... }
fn read_i32_le_checked(&mut self) -> Option<i32> { ... }
fn try_read_i32_le(&mut self) -> Result<i32, TryReadError> { ... }
fn read_i32_be(&mut self) -> i32 { ... }
fn read_i32_be_checked(&mut self) -> Option<i32> { ... }
fn try_read_i32_be(&mut self) -> Result<i32, TryReadError> { ... }
fn read_i32_ne(&mut self) -> i32 { ... }
fn read_i32_ne_checked(&mut self) -> Option<i32> { ... }
fn try_read_i32_ne(&mut self) -> Result<i32, TryReadError> { ... }
fn read_i64_le(&mut self) -> i64 { ... }
fn read_i64_le_checked(&mut self) -> Option<i64> { ... }
fn try_read_i64_le(&mut self) -> Result<i64, TryReadError> { ... }
fn read_i64_be(&mut self) -> i64 { ... }
fn read_i64_be_checked(&mut self) -> Option<i64> { ... }
fn try_read_i64_be(&mut self) -> Result<i64, TryReadError> { ... }
fn read_i64_ne(&mut self) -> i64 { ... }
fn read_i64_ne_checked(&mut self) -> Option<i64> { ... }
fn try_read_i64_ne(&mut self) -> Result<i64, TryReadError> { ... }
fn read_i128_le(&mut self) -> i128 { ... }
fn read_i128_le_checked(&mut self) -> Option<i128> { ... }
fn try_read_i128_le(&mut self) -> Result<i128, TryReadError> { ... }
fn read_i128_be(&mut self) -> i128 { ... }
fn read_i128_be_checked(&mut self) -> Option<i128> { ... }
fn try_read_i128_be(&mut self) -> Result<i128, TryReadError> { ... }
fn read_i128_ne(&mut self) -> i128 { ... }
fn read_i128_ne_checked(&mut self) -> Option<i128> { ... }
fn try_read_i128_ne(&mut self) -> Result<i128, TryReadError> { ... }
fn read_f32_le(&mut self) -> f32 { ... }
fn read_f32_le_checked(&mut self) -> Option<f32> { ... }
fn try_read_f32_le(&mut self) -> Result<f32, TryReadError> { ... }
fn read_f32_be(&mut self) -> f32 { ... }
fn read_f32_be_checked(&mut self) -> Option<f32> { ... }
fn try_read_f32_be(&mut self) -> Result<f32, TryReadError> { ... }
fn read_f32_ne(&mut self) -> f32 { ... }
fn read_f32_ne_checked(&mut self) -> Option<f32> { ... }
fn try_read_f32_ne(&mut self) -> Result<f32, TryReadError> { ... }
fn read_f64_le(&mut self) -> f64 { ... }
fn read_f64_le_checked(&mut self) -> Option<f64> { ... }
fn try_read_f64_le(&mut self) -> Result<f64, TryReadError> { ... }
fn read_f64_be(&mut self) -> f64 { ... }
fn read_f64_be_checked(&mut self) -> Option<f64> { ... }
fn try_read_f64_be(&mut self) -> Result<f64, TryReadError> { ... }
fn read_f64_ne(&mut self) -> f64 { ... }
fn read_f64_ne_checked(&mut self) -> Option<f64> { ... }
fn try_read_f64_ne(&mut self) -> Result<f64, TryReadError> { ... }
fn peek_u8(&self) -> u8 { ... }
fn peek_u8_checked(&self) -> Option<u8> { ... }
fn try_peek_u8(&self) -> Result<u8, TryPeekError> { ... }
fn read_u8(&mut self) -> u8 { ... }
fn read_u8_checked(&mut self) -> Option<u8> { ... }
fn try_read_u8(&mut self) -> Result<u8, TryReadError> { ... }
fn peek_i8(&self) -> i8 { ... }
fn peek_i8_checked(&self) -> Option<i8> { ... }
fn try_peek_i8(&self) -> Result<i8, TryPeekError> { ... }
fn read_i8(&mut self) -> i8 { ... }
fn read_i8_checked(&mut self) -> Option<i8> { ... }
fn try_read_i8(&mut self) -> Result<i8, TryReadError> { ... }
fn to_vec(&self) -> Vec<u8> ⓘ { ... }
fn to_bytes(&self) -> Bytes { ... }
fn to_bytes_mut(&self) -> BytesMut { ... }
}Expand description
A trait for implementing custom buffers that can read and navigate through byte sequences.
This trait provides a comprehensive set of methods for reading data from buffers with different error handling strategies:
- Panicking methods (e.g.,
read_*): Fast operations that panic on insufficient data - Checked methods (e.g.,
*_checked): ReturnOption-Noneon failure,Some(value)on success - Fallible methods (e.g.,
try_*): ReturnResultwith detailed error information
§Method Categories
- Buffer inspection:
remaining(),has_remaining(),buffer() - Navigation:
advance(),try_advance() - Buffer manipulation:
truncate(),split_to(),split_off(),segment() - Peeking data:
peek_u8(),peek_u16_le(), etc. (read without advancing) - Reading data:
read_u8(),read_u16_le(), etc. (read and advance cursor)
Required Methods§
Sourcefn remaining(&self) -> usize
fn remaining(&self) -> usize
Returns the number of bytes available for reading in the buffer.
This represents how many bytes can be read from the current cursor position to the end of the buffer.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert_eq!(buf.remaining(), 5);
buf.advance(2);
assert_eq!(buf.remaining(), 3);Sourcefn buffer(&self) -> &[u8] ⓘ
fn buffer(&self) -> &[u8] ⓘ
Returns the remaining bytes of the buffer as a slice.
This provides direct access to all bytes from the current cursor position to the end of the buffer.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert_eq!(buf.buffer(), &[1, 2, 3, 4, 5]);
buf.advance(2);
assert_eq!(buf.buffer(), &[3, 4, 5]);Sourcefn advance(&mut self, cnt: usize)
fn advance(&mut self, cnt: usize)
Advances the internal cursor by the specified number of bytes.
This moves the read position forward, making the advanced bytes no longer available for reading. The operation consumes the bytes without returning them.
§Panics
Panics if cnt > self.remaining().
Use try_advance for non-panicking advancement.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
buf.advance(2);
assert_eq!(buf.remaining(), 3);
assert_eq!(buf.buffer(), &[3, 4, 5]);Sourcefn segment(&self, range: impl RangeBounds<usize>) -> Selfwhere
Self: Sized,
fn segment(&self, range: impl RangeBounds<usize>) -> Selfwhere
Self: Sized,
Creates an independent buffer containing a segment of the current buffer’s data.
This method returns a new buffer instance that represents a portion of the current buffer defined by the given range. The original buffer remains unchanged, and the new buffer has its own independent cursor starting at the beginning of the segment.
§Panics
Panics if the range is out of bounds relative to the current buffer’s available data.
Use try_segment for non-panicking segmentation.
§Examples
use bufkit::Buf;
let data = b"Hello, World!";
let buf = &data[..];
let hello = buf.segment(0..5);
let world = buf.segment(7..12);
assert_eq!(hello.buffer(), b"Hello");
assert_eq!(world.buffer(), b"World");
// Original buffer unchanged
assert_eq!(buf.remaining(), 13);Sourcefn truncate(&mut self, len: usize)
fn truncate(&mut self, len: usize)
Shortens the buffer to the specified length, keeping the first len bytes.
If len is greater than the buffer’s current available bytes, this has no effect.
This operation cannot fail and will never panic.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
buf.truncate(3);
assert_eq!(buf.remaining(), 3);
assert_eq!(buf.buffer(), &[1, 2, 3]);
// Truncating to a length >= available has no effect
buf.truncate(10);
assert_eq!(buf.remaining(), 3);Sourcefn split_off(&mut self, at: usize) -> Selfwhere
Self: Sized,
fn split_off(&mut self, at: usize) -> Selfwhere
Self: Sized,
Splits the buffer into two at the given index.
Afterwards self contains elements [0, at), and the returned buffer
contains elements [at, remaining()). The memory layout remains unchanged.
Implementor Notes: This should be an O(1) operation.
§Panics
Panics if at > self.remaining().
Use split_off_checked or
try_split_off for non-panicking splits.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
let tail = Buf::split_off(&mut buf, 2);
assert_eq!(buf.buffer(), &[1, 2]);
assert_eq!(tail.buffer(), &[3, 4, 5]);Sourcefn split_to(&mut self, at: usize) -> Selfwhere
Self: Sized,
fn split_to(&mut self, at: usize) -> Selfwhere
Self: Sized,
Splits the buffer into two at the given index.
Afterwards self contains elements [at, remaining()), and the returned
buffer contains elements [0, at).
Implementor Notes: This should be an O(1) operation.
§Panics
Panics if at > self.remaining().
Use split_to_checked or
try_split_to for non-panicking splits.
§Examples
use bufkit::Buf;
let data = b"hello world";
let mut buf = &data[..];
let hello = buf.split_to(5);
assert_eq!(hello.buffer(), b"hello");
assert_eq!(buf.buffer(), b" world");Provided Methods§
Sourcefn buffer_from(&self, offset: usize) -> &[u8] ⓘ
fn buffer_from(&self, offset: usize) -> &[u8] ⓘ
Returns a slice of the buffer starting from the specified offset.
This is similar to buffer but starts from the given offset
rather than the current cursor position.
§Panics
Panics if offset > self.remaining().
Use buffer_from_checked for non-panicking access.
§Examples
use bufkit::Buf;
let data = [1u8, 2, 3, 4, 5];
let buf = &data[..];
assert_eq!(buf.buffer(), &[1, 2, 3, 4, 5]);
assert_eq!(buf.buffer_from(2), &[3, 4, 5]);Sourcefn buffer_from_checked(&self, offset: usize) -> Option<&[u8]>
fn buffer_from_checked(&self, offset: usize) -> Option<&[u8]>
Returns a slice of the buffer starting from the specified offset.
This is the non-panicking version of buffer_from.
Returns Some(slice) if offset <= self.remaining(), otherwise returns None.
§Examples
use bufkit::Buf;
let data = [1u8, 2, 3, 4, 5];
let buf = &data[..];
assert_eq!(buf.buffer_from_checked(2), Some(&[3, 4, 5][..]));
assert!(buf.buffer_from_checked(5).unwrap().is_empty()); // empty buffer
assert_eq!(buf.buffer_from_checked(10), None); // Out of boundsSourcefn prefix(&self, len: usize) -> &[u8] ⓘ
fn prefix(&self, len: usize) -> &[u8] ⓘ
Returns a slice containing the first len bytes of the buffer.
This provides access to a prefix of the buffer for efficient manipulation of a specific portion without affecting the rest of the buffer.
§Panics
Panics if len > self.remaining().
Use prefix_checked for non-panicking access.
§Examples
use bufkit::Buf;
let mut buf = [1u8, 2, 3, 4, 5];
let slice = &buf[..];
let prefix = Buf::prefix(&slice, 3);
assert_eq!(prefix, [1u8, 2, 3].as_slice());Sourcefn prefix_checked(&self, len: usize) -> Option<&[u8]>
fn prefix_checked(&self, len: usize) -> Option<&[u8]>
Returns a slice containing the first len bytes of the buffer.
This is the non-panicking version of prefix.
Returns Some(slice) if len <= self.remaining(), otherwise returns None.
§Examples
use bufkit::Buf;
let mut buf = [1u8, 2, 3, 4, 5];
assert_eq!(Buf::prefix_checked(&&buf[..], 3).unwrap(), &[1, 2, 3]);
assert_eq!(Buf::prefix_checked(&&buf[..], 5).unwrap(), &[1, 2, 3, 4, 5]);
assert!(Buf::prefix_checked(&&buf[..], 10).is_none());Sourcefn suffix(&self, len: usize) -> &[u8] ⓘ
fn suffix(&self, len: usize) -> &[u8] ⓘ
Returns a slice containing the last len bytes of the buffer.
This provides access to a suffix of the buffer for efficient manipulation of the trailing portion without affecting the rest of the buffer.
§Panics
Panics if len > self.remaining().
Use suffix_checked for non-panicking access.
§Examples
use bufkit::Buf;
let mut buf = [1u8, 2, 3, 4, 5];
let slice = &buf[..];
let suffix = Buf::suffix(&slice, 2);
assert_eq!(suffix, &[4, 5]);Sourcefn suffix_checked(&self, len: usize) -> Option<&[u8]>
fn suffix_checked(&self, len: usize) -> Option<&[u8]>
Returns a slice containing the last len bytes of the buffer.
This is the non-panicking version of suffix.
Returns Some(slice) if len <= self.remaining(), otherwise returns None.
§Examples
use bufkit::Buf;
let mut buf = [1u8, 2, 3, 4, 5];
let slice = &buf[..];
assert_eq!(Buf::suffix_checked(&slice, 2).unwrap(), &[4, 5]);
assert_eq!(Buf::suffix_checked(&slice, 5).unwrap(), &[1, 2, 3, 4, 5]);
assert!(Buf::suffix_checked(&slice, 10).is_none());Sourcefn split_off_checked(&mut self, at: usize) -> Option<Self>where
Self: Sized,
fn split_off_checked(&mut self, at: usize) -> Option<Self>where
Self: Sized,
Splits the buffer into two at the given index.
This is the non-panicking version of split_off.
Returns Some((left, right)) if at <= self.remaining(), otherwise returns None.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert!(Buf::split_off_checked(&mut buf, 2).is_some());
let mut small_buf = &[1u8][..];
assert!(Buf::split_off_checked(&mut small_buf, 5).is_none());Sourcefn try_split_off(&mut self, at: usize) -> Result<Self, OutOfBounds>where
Self: Sized,
fn try_split_off(&mut self, at: usize) -> Result<Self, OutOfBounds>where
Self: Sized,
Splits the buffer into two at the given index.
This is the non-panicking version of split_off that
returns detailed error information on failure.
Returns Ok(right_half) on success, or Err(OutOfBounds) with details about
the attempted split position and available bytes.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert!(Buf::try_split_off(&mut buf, 2).is_ok());
let mut small_buf = &[1u8][..];
let err = Buf::try_split_off(&mut small_buf, 5).unwrap_err();
// err contains details about requested vs availableSourcefn split_to_checked(&mut self, at: usize) -> Option<Self>where
Self: Sized,
fn split_to_checked(&mut self, at: usize) -> Option<Self>where
Self: Sized,
Splits the buffer into two at the given index.
This is the non-panicking version of split_to.
Returns Some(left_half) if at <= self.remaining(), otherwise returns None.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert!(Buf::split_to_checked(&mut buf, 3).is_some());
assert!(Buf::split_to_checked(&mut buf, 10).is_none());Sourcefn try_split_to(&mut self, at: usize) -> Result<Self, OutOfBounds>where
Self: Sized,
fn try_split_to(&mut self, at: usize) -> Result<Self, OutOfBounds>where
Self: Sized,
Splits the buffer into two at the given index.
This is the non-panicking version of split_to that
returns detailed error information on failure.
Returns Ok(left_half) on success, or Err(OutOfBounds) with details about
the attempted split position and available bytes.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert!(Buf::try_split_to(&mut buf, 3).is_ok());
let err = Buf::try_split_to(&mut buf, 10).unwrap_err();
// err contains detailed information about the failureSourcefn has_remaining(&self) -> bool
fn has_remaining(&self) -> bool
Returns true if there are bytes available for reading in the buffer.
This is equivalent to self.remaining() > 0.
§Examples
use bufkit::Buf;
let data = [1, 2, 3];
let mut buf = &data[..];
assert!(Buf::has_remaining(&buf));
buf.advance(3);
assert!(!Buf::has_remaining(&buf));Sourcefn try_advance(&mut self, cnt: usize) -> Result<(), TryAdvanceError>
fn try_advance(&mut self, cnt: usize) -> Result<(), TryAdvanceError>
Attempts to advance the internal cursor by the specified number of bytes.
This is the non-panicking version of advance.
Returns Ok(()) if the advancement was successful, or Err(TryAdvanceError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let mut buf = &data[..];
assert!(buf.try_advance(3).is_ok());
assert_eq!(buf.remaining(), 2);
let err = buf.try_advance(5).unwrap_err();
// err contains details about requested vs availableSourcefn try_segment(
&self,
range: impl RangeBounds<usize>,
) -> Result<Self, TrySegmentError>where
Self: Sized,
fn try_segment(
&self,
range: impl RangeBounds<usize>,
) -> Result<Self, TrySegmentError>where
Self: Sized,
Attempts to create a new buffer containing a segment of the current buffer’s data.
The returned buffer is independent with its own cursor starting at the beginning of the segment.
The original buffer remains unchanged. This is the non-panicking version of
segment.
Returns Ok(segment) if the range is valid, or Err(TrySegmentError) if the range
extends beyond the current buffer’s available data.
§Examples
use bufkit::Buf;
let data = b"Hello, World!";
let buf = &data[..];
assert!(buf.try_segment(0..5).is_ok());
assert!(buf.try_segment(0..20).is_err()); // Out of boundsSourcefn peek_u16_le(&self) -> u16
fn peek_u16_le(&self) -> u16
Peeks a u16 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u16_le(), <u16>::from_le_bytes((&data[..size_of::<u16>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u16_le_checked(&self) -> Option<u16>
fn peek_u16_le_checked(&self) -> Option<u16>
Peeks a u16 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u16_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u16_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u16_le_checked().is_none()); // Not enough bytesSourcefn try_peek_u16_le(&self) -> Result<u16, TryPeekError>
fn try_peek_u16_le(&self) -> Result<u16, TryPeekError>
Peeks a u16 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u16_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u16_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u16_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u16_be(&self) -> u16
fn peek_u16_be(&self) -> u16
Peeks a u16 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u16_be(), <u16>::from_be_bytes((&data[..size_of::<u16>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u16_be_checked(&self) -> Option<u16>
fn peek_u16_be_checked(&self) -> Option<u16>
Peeks a u16 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u16_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u16_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_u16_be_checked().is_none()); // Not enough bytesSourcefn try_peek_u16_be(&self) -> Result<u16, TryPeekError>
fn try_peek_u16_be(&self) -> Result<u16, TryPeekError>
Peeks a u16 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u16_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u16_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_u16_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u16_ne(&self) -> u16
fn peek_u16_ne(&self) -> u16
Peeks a u16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_u16_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u16_ne_checked(&self) -> Option<u16>
fn peek_u16_ne_checked(&self) -> Option<u16>
Peeks a u16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u16_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u16_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u16_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_u16_ne(&self) -> Result<u16, TryPeekError>
fn try_peek_u16_ne(&self) -> Result<u16, TryPeekError>
Peeks a u16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u16_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u16_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u16_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u32_le(&self) -> u32
fn peek_u32_le(&self) -> u32
Peeks a u32 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u32_le(), <u32>::from_le_bytes((&data[..size_of::<u32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u32_le_checked(&self) -> Option<u32>
fn peek_u32_le_checked(&self) -> Option<u32>
Peeks a u32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u32_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u32_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u32_le_checked().is_none()); // Not enough bytesSourcefn try_peek_u32_le(&self) -> Result<u32, TryPeekError>
fn try_peek_u32_le(&self) -> Result<u32, TryPeekError>
Peeks a u32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u32_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u32_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u32_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u32_be(&self) -> u32
fn peek_u32_be(&self) -> u32
Peeks a u32 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u32_be(), <u32>::from_be_bytes((&data[..size_of::<u32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u32_be_checked(&self) -> Option<u32>
fn peek_u32_be_checked(&self) -> Option<u32>
Peeks a u32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u32_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u32_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_u32_be_checked().is_none()); // Not enough bytesSourcefn try_peek_u32_be(&self) -> Result<u32, TryPeekError>
fn try_peek_u32_be(&self) -> Result<u32, TryPeekError>
Peeks a u32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u32_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u32_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_u32_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u32_ne(&self) -> u32
fn peek_u32_ne(&self) -> u32
Peeks a u32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_u32_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u32_ne_checked(&self) -> Option<u32>
fn peek_u32_ne_checked(&self) -> Option<u32>
Peeks a u32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u32_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u32_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u32_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_u32_ne(&self) -> Result<u32, TryPeekError>
fn try_peek_u32_ne(&self) -> Result<u32, TryPeekError>
Peeks a u32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u32_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u32_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u32_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u64_le(&self) -> u64
fn peek_u64_le(&self) -> u64
Peeks a u64 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u64_le(), <u64>::from_le_bytes((&data[..size_of::<u64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u64_le_checked(&self) -> Option<u64>
fn peek_u64_le_checked(&self) -> Option<u64>
Peeks a u64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u64_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u64_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u64_le_checked().is_none()); // Not enough bytesSourcefn try_peek_u64_le(&self) -> Result<u64, TryPeekError>
fn try_peek_u64_le(&self) -> Result<u64, TryPeekError>
Peeks a u64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u64_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u64_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u64_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u64_be(&self) -> u64
fn peek_u64_be(&self) -> u64
Peeks a u64 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u64_be(), <u64>::from_be_bytes((&data[..size_of::<u64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u64_be_checked(&self) -> Option<u64>
fn peek_u64_be_checked(&self) -> Option<u64>
Peeks a u64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u64_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u64_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_u64_be_checked().is_none()); // Not enough bytesSourcefn try_peek_u64_be(&self) -> Result<u64, TryPeekError>
fn try_peek_u64_be(&self) -> Result<u64, TryPeekError>
Peeks a u64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u64_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u64_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_u64_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u64_ne(&self) -> u64
fn peek_u64_ne(&self) -> u64
Peeks a u64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_u64_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u64_ne_checked(&self) -> Option<u64>
fn peek_u64_ne_checked(&self) -> Option<u64>
Peeks a u64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u64_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u64_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u64_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_u64_ne(&self) -> Result<u64, TryPeekError>
fn try_peek_u64_ne(&self) -> Result<u64, TryPeekError>
Peeks a u64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u64_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u64_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u64_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u128_le(&self) -> u128
fn peek_u128_le(&self) -> u128
Peeks a u128 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u128_le(), <u128>::from_le_bytes((&data[..size_of::<u128>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u128_le_checked(&self) -> Option<u128>
fn peek_u128_le_checked(&self) -> Option<u128>
Peeks a u128 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u128_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u128_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u128_le_checked().is_none()); // Not enough bytesSourcefn try_peek_u128_le(&self) -> Result<u128, TryPeekError>
fn try_peek_u128_le(&self) -> Result<u128, TryPeekError>
Peeks a u128 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u128_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u128_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u128_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u128_be(&self) -> u128
fn peek_u128_be(&self) -> u128
Peeks a u128 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_u128_be(), <u128>::from_be_bytes((&data[..size_of::<u128>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u128_be_checked(&self) -> Option<u128>
fn peek_u128_be_checked(&self) -> Option<u128>
Peeks a u128 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u128_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u128_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_u128_be_checked().is_none()); // Not enough bytesSourcefn try_peek_u128_be(&self) -> Result<u128, TryPeekError>
fn try_peek_u128_be(&self) -> Result<u128, TryPeekError>
Peeks a u128 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_u128_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u128_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_u128_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_u128_ne(&self) -> u128
fn peek_u128_ne(&self) -> u128
Peeks a u128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_u128_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_u128_ne_checked(&self) -> Option<u128>
fn peek_u128_ne_checked(&self) -> Option<u128>
Peeks a u128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u128_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_u128_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_u128_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_u128_ne(&self) -> Result<u128, TryPeekError>
fn try_peek_u128_ne(&self) -> Result<u128, TryPeekError>
Peeks a u128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_u128_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_u128_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_u128_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i16_le(&self) -> i16
fn peek_i16_le(&self) -> i16
Peeks a i16 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i16_le(), <i16>::from_le_bytes((&data[..size_of::<i16>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i16_le_checked(&self) -> Option<i16>
fn peek_i16_le_checked(&self) -> Option<i16>
Peeks a i16 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i16_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i16_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i16_le_checked().is_none()); // Not enough bytesSourcefn try_peek_i16_le(&self) -> Result<i16, TryPeekError>
fn try_peek_i16_le(&self) -> Result<i16, TryPeekError>
Peeks a i16 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i16_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i16_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i16_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i16_be(&self) -> i16
fn peek_i16_be(&self) -> i16
Peeks a i16 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i16_be(), <i16>::from_be_bytes((&data[..size_of::<i16>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i16_be_checked(&self) -> Option<i16>
fn peek_i16_be_checked(&self) -> Option<i16>
Peeks a i16 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i16_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i16_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_i16_be_checked().is_none()); // Not enough bytesSourcefn try_peek_i16_be(&self) -> Result<i16, TryPeekError>
fn try_peek_i16_be(&self) -> Result<i16, TryPeekError>
Peeks a i16 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i16_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i16_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_i16_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i16_ne(&self) -> i16
fn peek_i16_ne(&self) -> i16
Peeks a i16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_i16_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i16_ne_checked(&self) -> Option<i16>
fn peek_i16_ne_checked(&self) -> Option<i16>
Peeks a i16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i16_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i16_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i16_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_i16_ne(&self) -> Result<i16, TryPeekError>
fn try_peek_i16_ne(&self) -> Result<i16, TryPeekError>
Peeks a i16 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i16_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i16_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i16_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i32_le(&self) -> i32
fn peek_i32_le(&self) -> i32
Peeks a i32 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i32_le(), <i32>::from_le_bytes((&data[..size_of::<i32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i32_le_checked(&self) -> Option<i32>
fn peek_i32_le_checked(&self) -> Option<i32>
Peeks a i32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i32_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i32_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i32_le_checked().is_none()); // Not enough bytesSourcefn try_peek_i32_le(&self) -> Result<i32, TryPeekError>
fn try_peek_i32_le(&self) -> Result<i32, TryPeekError>
Peeks a i32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i32_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i32_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i32_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i32_be(&self) -> i32
fn peek_i32_be(&self) -> i32
Peeks a i32 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i32_be(), <i32>::from_be_bytes((&data[..size_of::<i32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i32_be_checked(&self) -> Option<i32>
fn peek_i32_be_checked(&self) -> Option<i32>
Peeks a i32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i32_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i32_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_i32_be_checked().is_none()); // Not enough bytesSourcefn try_peek_i32_be(&self) -> Result<i32, TryPeekError>
fn try_peek_i32_be(&self) -> Result<i32, TryPeekError>
Peeks a i32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i32_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i32_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_i32_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i32_ne(&self) -> i32
fn peek_i32_ne(&self) -> i32
Peeks a i32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_i32_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i32_ne_checked(&self) -> Option<i32>
fn peek_i32_ne_checked(&self) -> Option<i32>
Peeks a i32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i32_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i32_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i32_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_i32_ne(&self) -> Result<i32, TryPeekError>
fn try_peek_i32_ne(&self) -> Result<i32, TryPeekError>
Peeks a i32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i32_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i32_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i32_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i64_le(&self) -> i64
fn peek_i64_le(&self) -> i64
Peeks a i64 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i64_le(), <i64>::from_le_bytes((&data[..size_of::<i64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i64_le_checked(&self) -> Option<i64>
fn peek_i64_le_checked(&self) -> Option<i64>
Peeks a i64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i64_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i64_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i64_le_checked().is_none()); // Not enough bytesSourcefn try_peek_i64_le(&self) -> Result<i64, TryPeekError>
fn try_peek_i64_le(&self) -> Result<i64, TryPeekError>
Peeks a i64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i64_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i64_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i64_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i64_be(&self) -> i64
fn peek_i64_be(&self) -> i64
Peeks a i64 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i64_be(), <i64>::from_be_bytes((&data[..size_of::<i64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i64_be_checked(&self) -> Option<i64>
fn peek_i64_be_checked(&self) -> Option<i64>
Peeks a i64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i64_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i64_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_i64_be_checked().is_none()); // Not enough bytesSourcefn try_peek_i64_be(&self) -> Result<i64, TryPeekError>
fn try_peek_i64_be(&self) -> Result<i64, TryPeekError>
Peeks a i64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i64_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i64_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_i64_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i64_ne(&self) -> i64
fn peek_i64_ne(&self) -> i64
Peeks a i64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_i64_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i64_ne_checked(&self) -> Option<i64>
fn peek_i64_ne_checked(&self) -> Option<i64>
Peeks a i64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i64_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i64_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i64_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_i64_ne(&self) -> Result<i64, TryPeekError>
fn try_peek_i64_ne(&self) -> Result<i64, TryPeekError>
Peeks a i64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i64_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i64_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i64_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i128_le(&self) -> i128
fn peek_i128_le(&self) -> i128
Peeks a i128 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i128_le(), <i128>::from_le_bytes((&data[..size_of::<i128>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i128_le_checked(&self) -> Option<i128>
fn peek_i128_le_checked(&self) -> Option<i128>
Peeks a i128 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i128_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i128_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i128_le_checked().is_none()); // Not enough bytesSourcefn try_peek_i128_le(&self) -> Result<i128, TryPeekError>
fn try_peek_i128_le(&self) -> Result<i128, TryPeekError>
Peeks a i128 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i128_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i128_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i128_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i128_be(&self) -> i128
fn peek_i128_be(&self) -> i128
Peeks a i128 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_i128_be(), <i128>::from_be_bytes((&data[..size_of::<i128>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i128_be_checked(&self) -> Option<i128>
fn peek_i128_be_checked(&self) -> Option<i128>
Peeks a i128 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i128_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i128_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_i128_be_checked().is_none()); // Not enough bytesSourcefn try_peek_i128_be(&self) -> Result<i128, TryPeekError>
fn try_peek_i128_be(&self) -> Result<i128, TryPeekError>
Peeks a i128 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_i128_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i128_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_i128_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_i128_ne(&self) -> i128
fn peek_i128_ne(&self) -> i128
Peeks a i128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_i128_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_i128_ne_checked(&self) -> Option<i128>
fn peek_i128_ne_checked(&self) -> Option<i128>
Peeks a i128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i128_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_i128_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_i128_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_i128_ne(&self) -> Result<i128, TryPeekError>
fn try_peek_i128_ne(&self) -> Result<i128, TryPeekError>
Peeks a i128 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_i128_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_i128_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_i128_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f32_le(&self) -> f32
fn peek_f32_le(&self) -> f32
Peeks a f32 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_f32_le(), <f32>::from_le_bytes((&data[..size_of::<f32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f32_le_checked(&self) -> Option<f32>
fn peek_f32_le_checked(&self) -> Option<f32>
Peeks a f32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f32_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f32_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_f32_le_checked().is_none()); // Not enough bytesSourcefn try_peek_f32_le(&self) -> Result<f32, TryPeekError>
fn try_peek_f32_le(&self) -> Result<f32, TryPeekError>
Peeks a f32 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f32_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f32_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_f32_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f32_be(&self) -> f32
fn peek_f32_be(&self) -> f32
Peeks a f32 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_f32_be(), <f32>::from_be_bytes((&data[..size_of::<f32>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f32_be_checked(&self) -> Option<f32>
fn peek_f32_be_checked(&self) -> Option<f32>
Peeks a f32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f32_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f32_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_f32_be_checked().is_none()); // Not enough bytesSourcefn try_peek_f32_be(&self) -> Result<f32, TryPeekError>
fn try_peek_f32_be(&self) -> Result<f32, TryPeekError>
Peeks a f32 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f32_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f32_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_f32_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f32_ne(&self) -> f32
fn peek_f32_ne(&self) -> f32
Peeks a f32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_f32_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f32_ne_checked(&self) -> Option<f32>
fn peek_f32_ne_checked(&self) -> Option<f32>
Peeks a f32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_f32_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f32_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_f32_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_f32_ne(&self) -> Result<f32, TryPeekError>
fn try_peek_f32_ne(&self) -> Result<f32, TryPeekError>
Peeks a f32 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_f32_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f32_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_f32_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f64_le(&self) -> f64
fn peek_f64_le(&self) -> f64
Peeks a f64 value from the buffer in little-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_f64_le(), <f64>::from_le_bytes((&data[..size_of::<f64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f64_le_checked(&self) -> Option<f64>
fn peek_f64_le_checked(&self) -> Option<f64>
Peeks a f64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f64_le.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f64_le_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_f64_le_checked().is_none()); // Not enough bytesSourcefn try_peek_f64_le(&self) -> Result<f64, TryPeekError>
fn try_peek_f64_le(&self) -> Result<f64, TryPeekError>
Peeks a f64 value from the buffer in little-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f64_le.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f64_le().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_f64_le().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f64_be(&self) -> f64
fn peek_f64_be(&self) -> f64
Peeks a f64 value from the buffer in big-endian byte order without advancing the cursor.
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert_eq!(buf.peek_f64_be(), <f64>::from_be_bytes((&data[..size_of::<f64>()]).try_into().unwrap()));
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f64_be_checked(&self) -> Option<f64>
fn peek_f64_be_checked(&self) -> Option<f64>
Peeks a f64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f64_be.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f64_be_checked().is_some());
let small_buf = &[0x12][..];
assert!(small_buf.peek_f64_be_checked().is_none()); // Not enough bytesSourcefn try_peek_f64_be(&self) -> Result<f64, TryPeekError>
fn try_peek_f64_be(&self) -> Result<f64, TryPeekError>
Peeks a f64 value from the buffer in big-endian byte order without advancing the cursor.
This is the non-panicking version of peek_f64_be.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f64_be().is_ok());
let small_buf = &[0x12][..];
let err = small_buf.try_peek_f64_be().unwrap_err();
// err contains details about requested vs available bytesSourcefn peek_f64_ne(&self) -> f64
fn peek_f64_ne(&self) -> f64
Peeks a f64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
let value = buf.peek_f64_ne();
assert_eq!(buf.remaining(), data.len()); // Cursor unchangedSourcefn peek_f64_ne_checked(&self) -> Option<f64>
fn peek_f64_ne_checked(&self) -> Option<f64>
Peeks a f64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_f64_ne.
Returns Some(value) if sufficient data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.peek_f64_ne_checked().is_some());
let small_buf = &[0x34][..];
assert!(small_buf.peek_f64_ne_checked().is_none()); // Not enough bytesSourcefn try_peek_f64_ne(&self) -> Result<f64, TryPeekError>
fn try_peek_f64_ne(&self) -> Result<f64, TryPeekError>
Peeks a f64 value from the buffer in native-endian byte order without advancing the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of peek_f64_ne.
Returns Ok(value) on success, or Err(TryPeekError) with details about
requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let buf = &data[..];
assert!(buf.try_peek_f64_ne().is_ok());
let small_buf = &[0x34][..];
let err = small_buf.try_peek_f64_ne().unwrap_err();
// err contains details about requested vs available bytesSourcefn read_u16_le(&mut self) -> u16
fn read_u16_le(&mut self) -> u16
Reads a u16 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u16_le();
assert_eq!(buf.remaining(), data.len() - size_of::<u16>()); // Cursor advancedSourcefn read_u16_le_checked(&mut self) -> Option<u16>
fn read_u16_le_checked(&mut self) -> Option<u16>
Reads a u16 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u16_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u16_le_checked() {
// Cursor advanced by size_of::<u16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u16_le(&mut self) -> Result<u16, TryReadError>
fn try_read_u16_le(&mut self) -> Result<u16, TryReadError>
Reads a u16 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u16_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u16_le() {
Ok(value) => {
// Cursor advanced by size_of::<u16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u16_be(&mut self) -> u16
fn read_u16_be(&mut self) -> u16
Reads a u16 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u16_be();
assert_eq!(buf.remaining(), data.len() - size_of::<u16>()); // Cursor advancedSourcefn read_u16_be_checked(&mut self) -> Option<u16>
fn read_u16_be_checked(&mut self) -> Option<u16>
Reads a u16 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u16_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u16_be_checked() {
// Cursor advanced by size_of::<u16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u16_be(&mut self) -> Result<u16, TryReadError>
fn try_read_u16_be(&mut self) -> Result<u16, TryReadError>
Reads a u16 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u16_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u16_be() {
Ok(value) => {
// Cursor advanced by size_of::<u16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u16_ne(&mut self) -> u16
fn read_u16_ne(&mut self) -> u16
Reads a u16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<u16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u16_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<u16>()); // Cursor advancedSourcefn read_u16_ne_checked(&mut self) -> Option<u16>
fn read_u16_ne_checked(&mut self) -> Option<u16>
Reads a u16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u16_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u16_ne_checked() {
// Cursor advanced by size_of::<u16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u16_ne(&mut self) -> Result<u16, TryReadError>
fn try_read_u16_ne(&mut self) -> Result<u16, TryReadError>
Reads a u16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u16_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u16_ne() {
Ok(value) => {
// Cursor advanced by size_of::<u16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u32_le(&mut self) -> u32
fn read_u32_le(&mut self) -> u32
Reads a u32 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u32_le();
assert_eq!(buf.remaining(), data.len() - size_of::<u32>()); // Cursor advancedSourcefn read_u32_le_checked(&mut self) -> Option<u32>
fn read_u32_le_checked(&mut self) -> Option<u32>
Reads a u32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u32_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u32_le_checked() {
// Cursor advanced by size_of::<u32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u32_le(&mut self) -> Result<u32, TryReadError>
fn try_read_u32_le(&mut self) -> Result<u32, TryReadError>
Reads a u32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u32_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u32_le() {
Ok(value) => {
// Cursor advanced by size_of::<u32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u32_be(&mut self) -> u32
fn read_u32_be(&mut self) -> u32
Reads a u32 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u32_be();
assert_eq!(buf.remaining(), data.len() - size_of::<u32>()); // Cursor advancedSourcefn read_u32_be_checked(&mut self) -> Option<u32>
fn read_u32_be_checked(&mut self) -> Option<u32>
Reads a u32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u32_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u32_be_checked() {
// Cursor advanced by size_of::<u32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u32_be(&mut self) -> Result<u32, TryReadError>
fn try_read_u32_be(&mut self) -> Result<u32, TryReadError>
Reads a u32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u32_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u32_be() {
Ok(value) => {
// Cursor advanced by size_of::<u32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u32_ne(&mut self) -> u32
fn read_u32_ne(&mut self) -> u32
Reads a u32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<u32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u32_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<u32>()); // Cursor advancedSourcefn read_u32_ne_checked(&mut self) -> Option<u32>
fn read_u32_ne_checked(&mut self) -> Option<u32>
Reads a u32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u32_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u32_ne_checked() {
// Cursor advanced by size_of::<u32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u32_ne(&mut self) -> Result<u32, TryReadError>
fn try_read_u32_ne(&mut self) -> Result<u32, TryReadError>
Reads a u32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u32_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u32_ne() {
Ok(value) => {
// Cursor advanced by size_of::<u32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u64_le(&mut self) -> u64
fn read_u64_le(&mut self) -> u64
Reads a u64 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u64_le();
assert_eq!(buf.remaining(), data.len() - size_of::<u64>()); // Cursor advancedSourcefn read_u64_le_checked(&mut self) -> Option<u64>
fn read_u64_le_checked(&mut self) -> Option<u64>
Reads a u64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u64_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u64_le_checked() {
// Cursor advanced by size_of::<u64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u64_le(&mut self) -> Result<u64, TryReadError>
fn try_read_u64_le(&mut self) -> Result<u64, TryReadError>
Reads a u64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u64_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u64_le() {
Ok(value) => {
// Cursor advanced by size_of::<u64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u64_be(&mut self) -> u64
fn read_u64_be(&mut self) -> u64
Reads a u64 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u64_be();
assert_eq!(buf.remaining(), data.len() - size_of::<u64>()); // Cursor advancedSourcefn read_u64_be_checked(&mut self) -> Option<u64>
fn read_u64_be_checked(&mut self) -> Option<u64>
Reads a u64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u64_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u64_be_checked() {
// Cursor advanced by size_of::<u64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u64_be(&mut self) -> Result<u64, TryReadError>
fn try_read_u64_be(&mut self) -> Result<u64, TryReadError>
Reads a u64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u64_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u64_be() {
Ok(value) => {
// Cursor advanced by size_of::<u64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u64_ne(&mut self) -> u64
fn read_u64_ne(&mut self) -> u64
Reads a u64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<u64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u64_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<u64>()); // Cursor advancedSourcefn read_u64_ne_checked(&mut self) -> Option<u64>
fn read_u64_ne_checked(&mut self) -> Option<u64>
Reads a u64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u64_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u64_ne_checked() {
// Cursor advanced by size_of::<u64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u64_ne(&mut self) -> Result<u64, TryReadError>
fn try_read_u64_ne(&mut self) -> Result<u64, TryReadError>
Reads a u64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u64_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u64_ne() {
Ok(value) => {
// Cursor advanced by size_of::<u64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u128_le(&mut self) -> u128
fn read_u128_le(&mut self) -> u128
Reads a u128 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u128_le();
assert_eq!(buf.remaining(), data.len() - size_of::<u128>()); // Cursor advancedSourcefn read_u128_le_checked(&mut self) -> Option<u128>
fn read_u128_le_checked(&mut self) -> Option<u128>
Reads a u128 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u128_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u128_le_checked() {
// Cursor advanced by size_of::<u128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u128_le(&mut self) -> Result<u128, TryReadError>
fn try_read_u128_le(&mut self) -> Result<u128, TryReadError>
Reads a u128 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_u128_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u128_le() {
Ok(value) => {
// Cursor advanced by size_of::<u128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u128_be(&mut self) -> u128
fn read_u128_be(&mut self) -> u128
Reads a u128 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<u128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u128_be();
assert_eq!(buf.remaining(), data.len() - size_of::<u128>()); // Cursor advancedSourcefn read_u128_be_checked(&mut self) -> Option<u128>
fn read_u128_be_checked(&mut self) -> Option<u128>
Reads a u128 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u128_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u128_be_checked() {
// Cursor advanced by size_of::<u128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u128_be(&mut self) -> Result<u128, TryReadError>
fn try_read_u128_be(&mut self) -> Result<u128, TryReadError>
Reads a u128 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_u128_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u128_be() {
Ok(value) => {
// Cursor advanced by size_of::<u128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_u128_ne(&mut self) -> u128
fn read_u128_ne(&mut self) -> u128
Reads a u128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<u128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<u128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_u128_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<u128>()); // Cursor advancedSourcefn read_u128_ne_checked(&mut self) -> Option<u128>
fn read_u128_ne_checked(&mut self) -> Option<u128>
Reads a u128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u128_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_u128_ne_checked() {
// Cursor advanced by size_of::<u128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_u128_ne(&mut self) -> Result<u128, TryReadError>
fn try_read_u128_ne(&mut self) -> Result<u128, TryReadError>
Reads a u128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_u128_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_u128_ne() {
Ok(value) => {
// Cursor advanced by size_of::<u128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i16_le(&mut self) -> i16
fn read_i16_le(&mut self) -> i16
Reads a i16 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i16_le();
assert_eq!(buf.remaining(), data.len() - size_of::<i16>()); // Cursor advancedSourcefn read_i16_le_checked(&mut self) -> Option<i16>
fn read_i16_le_checked(&mut self) -> Option<i16>
Reads a i16 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i16_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i16_le_checked() {
// Cursor advanced by size_of::<i16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i16_le(&mut self) -> Result<i16, TryReadError>
fn try_read_i16_le(&mut self) -> Result<i16, TryReadError>
Reads a i16 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i16_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i16_le() {
Ok(value) => {
// Cursor advanced by size_of::<i16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i16_be(&mut self) -> i16
fn read_i16_be(&mut self) -> i16
Reads a i16 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i16_be();
assert_eq!(buf.remaining(), data.len() - size_of::<i16>()); // Cursor advancedSourcefn read_i16_be_checked(&mut self) -> Option<i16>
fn read_i16_be_checked(&mut self) -> Option<i16>
Reads a i16 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i16_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i16_be_checked() {
// Cursor advanced by size_of::<i16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i16_be(&mut self) -> Result<i16, TryReadError>
fn try_read_i16_be(&mut self) -> Result<i16, TryReadError>
Reads a i16 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i16_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i16_be() {
Ok(value) => {
// Cursor advanced by size_of::<i16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i16_ne(&mut self) -> i16
fn read_i16_ne(&mut self) -> i16
Reads a i16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<i16>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i16>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i16_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<i16>()); // Cursor advancedSourcefn read_i16_ne_checked(&mut self) -> Option<i16>
fn read_i16_ne_checked(&mut self) -> Option<i16>
Reads a i16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i16_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i16_ne_checked() {
// Cursor advanced by size_of::<i16>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i16_ne(&mut self) -> Result<i16, TryReadError>
fn try_read_i16_ne(&mut self) -> Result<i16, TryReadError>
Reads a i16 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i16_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i16_ne() {
Ok(value) => {
// Cursor advanced by size_of::<i16>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i32_le(&mut self) -> i32
fn read_i32_le(&mut self) -> i32
Reads a i32 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i32_le();
assert_eq!(buf.remaining(), data.len() - size_of::<i32>()); // Cursor advancedSourcefn read_i32_le_checked(&mut self) -> Option<i32>
fn read_i32_le_checked(&mut self) -> Option<i32>
Reads a i32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i32_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i32_le_checked() {
// Cursor advanced by size_of::<i32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i32_le(&mut self) -> Result<i32, TryReadError>
fn try_read_i32_le(&mut self) -> Result<i32, TryReadError>
Reads a i32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i32_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i32_le() {
Ok(value) => {
// Cursor advanced by size_of::<i32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i32_be(&mut self) -> i32
fn read_i32_be(&mut self) -> i32
Reads a i32 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i32_be();
assert_eq!(buf.remaining(), data.len() - size_of::<i32>()); // Cursor advancedSourcefn read_i32_be_checked(&mut self) -> Option<i32>
fn read_i32_be_checked(&mut self) -> Option<i32>
Reads a i32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i32_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i32_be_checked() {
// Cursor advanced by size_of::<i32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i32_be(&mut self) -> Result<i32, TryReadError>
fn try_read_i32_be(&mut self) -> Result<i32, TryReadError>
Reads a i32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i32_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i32_be() {
Ok(value) => {
// Cursor advanced by size_of::<i32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i32_ne(&mut self) -> i32
fn read_i32_ne(&mut self) -> i32
Reads a i32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<i32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i32_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<i32>()); // Cursor advancedSourcefn read_i32_ne_checked(&mut self) -> Option<i32>
fn read_i32_ne_checked(&mut self) -> Option<i32>
Reads a i32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i32_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i32_ne_checked() {
// Cursor advanced by size_of::<i32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i32_ne(&mut self) -> Result<i32, TryReadError>
fn try_read_i32_ne(&mut self) -> Result<i32, TryReadError>
Reads a i32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i32_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i32_ne() {
Ok(value) => {
// Cursor advanced by size_of::<i32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i64_le(&mut self) -> i64
fn read_i64_le(&mut self) -> i64
Reads a i64 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i64_le();
assert_eq!(buf.remaining(), data.len() - size_of::<i64>()); // Cursor advancedSourcefn read_i64_le_checked(&mut self) -> Option<i64>
fn read_i64_le_checked(&mut self) -> Option<i64>
Reads a i64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i64_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i64_le_checked() {
// Cursor advanced by size_of::<i64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i64_le(&mut self) -> Result<i64, TryReadError>
fn try_read_i64_le(&mut self) -> Result<i64, TryReadError>
Reads a i64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i64_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i64_le() {
Ok(value) => {
// Cursor advanced by size_of::<i64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i64_be(&mut self) -> i64
fn read_i64_be(&mut self) -> i64
Reads a i64 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i64_be();
assert_eq!(buf.remaining(), data.len() - size_of::<i64>()); // Cursor advancedSourcefn read_i64_be_checked(&mut self) -> Option<i64>
fn read_i64_be_checked(&mut self) -> Option<i64>
Reads a i64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i64_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i64_be_checked() {
// Cursor advanced by size_of::<i64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i64_be(&mut self) -> Result<i64, TryReadError>
fn try_read_i64_be(&mut self) -> Result<i64, TryReadError>
Reads a i64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i64_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i64_be() {
Ok(value) => {
// Cursor advanced by size_of::<i64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i64_ne(&mut self) -> i64
fn read_i64_ne(&mut self) -> i64
Reads a i64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<i64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i64_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<i64>()); // Cursor advancedSourcefn read_i64_ne_checked(&mut self) -> Option<i64>
fn read_i64_ne_checked(&mut self) -> Option<i64>
Reads a i64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i64_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i64_ne_checked() {
// Cursor advanced by size_of::<i64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i64_ne(&mut self) -> Result<i64, TryReadError>
fn try_read_i64_ne(&mut self) -> Result<i64, TryReadError>
Reads a i64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i64_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i64_ne() {
Ok(value) => {
// Cursor advanced by size_of::<i64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i128_le(&mut self) -> i128
fn read_i128_le(&mut self) -> i128
Reads a i128 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i128_le();
assert_eq!(buf.remaining(), data.len() - size_of::<i128>()); // Cursor advancedSourcefn read_i128_le_checked(&mut self) -> Option<i128>
fn read_i128_le_checked(&mut self) -> Option<i128>
Reads a i128 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i128_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i128_le_checked() {
// Cursor advanced by size_of::<i128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i128_le(&mut self) -> Result<i128, TryReadError>
fn try_read_i128_le(&mut self) -> Result<i128, TryReadError>
Reads a i128 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_i128_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i128_le() {
Ok(value) => {
// Cursor advanced by size_of::<i128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i128_be(&mut self) -> i128
fn read_i128_be(&mut self) -> i128
Reads a i128 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<i128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i128_be();
assert_eq!(buf.remaining(), data.len() - size_of::<i128>()); // Cursor advancedSourcefn read_i128_be_checked(&mut self) -> Option<i128>
fn read_i128_be_checked(&mut self) -> Option<i128>
Reads a i128 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i128_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i128_be_checked() {
// Cursor advanced by size_of::<i128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i128_be(&mut self) -> Result<i128, TryReadError>
fn try_read_i128_be(&mut self) -> Result<i128, TryReadError>
Reads a i128 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_i128_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i128_be() {
Ok(value) => {
// Cursor advanced by size_of::<i128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_i128_ne(&mut self) -> i128
fn read_i128_ne(&mut self) -> i128
Reads a i128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<i128>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<i128>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_i128_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<i128>()); // Cursor advancedSourcefn read_i128_ne_checked(&mut self) -> Option<i128>
fn read_i128_ne_checked(&mut self) -> Option<i128>
Reads a i128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i128_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_i128_ne_checked() {
// Cursor advanced by size_of::<i128>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_i128_ne(&mut self) -> Result<i128, TryReadError>
fn try_read_i128_ne(&mut self) -> Result<i128, TryReadError>
Reads a i128 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_i128_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_i128_ne() {
Ok(value) => {
// Cursor advanced by size_of::<i128>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f32_le(&mut self) -> f32
fn read_f32_le(&mut self) -> f32
Reads a f32 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<f32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f32_le();
assert_eq!(buf.remaining(), data.len() - size_of::<f32>()); // Cursor advancedSourcefn read_f32_le_checked(&mut self) -> Option<f32>
fn read_f32_le_checked(&mut self) -> Option<f32>
Reads a f32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_f32_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f32_le_checked() {
// Cursor advanced by size_of::<f32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f32_le(&mut self) -> Result<f32, TryReadError>
fn try_read_f32_le(&mut self) -> Result<f32, TryReadError>
Reads a f32 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_f32_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f32_le() {
Ok(value) => {
// Cursor advanced by size_of::<f32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f32_be(&mut self) -> f32
fn read_f32_be(&mut self) -> f32
Reads a f32 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<f32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f32_be();
assert_eq!(buf.remaining(), data.len() - size_of::<f32>()); // Cursor advancedSourcefn read_f32_be_checked(&mut self) -> Option<f32>
fn read_f32_be_checked(&mut self) -> Option<f32>
Reads a f32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_f32_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f32_be_checked() {
// Cursor advanced by size_of::<f32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f32_be(&mut self) -> Result<f32, TryReadError>
fn try_read_f32_be(&mut self) -> Result<f32, TryReadError>
Reads a f32 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_f32_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f32_be() {
Ok(value) => {
// Cursor advanced by size_of::<f32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f32_ne(&mut self) -> f32
fn read_f32_ne(&mut self) -> f32
Reads a f32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<f32>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f32>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f32_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<f32>()); // Cursor advancedSourcefn read_f32_ne_checked(&mut self) -> Option<f32>
fn read_f32_ne_checked(&mut self) -> Option<f32>
Reads a f32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_f32_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f32_ne_checked() {
// Cursor advanced by size_of::<f32>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f32_ne(&mut self) -> Result<f32, TryReadError>
fn try_read_f32_ne(&mut self) -> Result<f32, TryReadError>
Reads a f32 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_f32_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f32_ne() {
Ok(value) => {
// Cursor advanced by size_of::<f32>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f64_le(&mut self) -> f64
fn read_f64_le(&mut self) -> f64
Reads a f64 value from the buffer in little-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<f64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f64_le();
assert_eq!(buf.remaining(), data.len() - size_of::<f64>()); // Cursor advancedSourcefn read_f64_le_checked(&mut self) -> Option<f64>
fn read_f64_le_checked(&mut self) -> Option<f64>
Reads a f64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_f64_le.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f64_le_checked() {
// Cursor advanced by size_of::<f64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f64_le(&mut self) -> Result<f64, TryReadError>
fn try_read_f64_le(&mut self) -> Result<f64, TryReadError>
Reads a f64 value from the buffer in little-endian byte order and advances the cursor.
This is the non-panicking version of read_f64_le.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f64_le() {
Ok(value) => {
// Cursor advanced by size_of::<f64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f64_be(&mut self) -> f64
fn read_f64_be(&mut self) -> f64
Reads a f64 value from the buffer in big-endian byte order and advances the cursor.
Returns the decoded value and advances the cursor by size_of::<f64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f64_be();
assert_eq!(buf.remaining(), data.len() - size_of::<f64>()); // Cursor advancedSourcefn read_f64_be_checked(&mut self) -> Option<f64>
fn read_f64_be_checked(&mut self) -> Option<f64>
Reads a f64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_f64_be.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f64_be_checked() {
// Cursor advanced by size_of::<f64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f64_be(&mut self) -> Result<f64, TryReadError>
fn try_read_f64_be(&mut self) -> Result<f64, TryReadError>
Reads a f64 value from the buffer in big-endian byte order and advances the cursor.
This is the non-panicking version of read_f64_be.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f64_be() {
Ok(value) => {
// Cursor advanced by size_of::<f64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn read_f64_ne(&mut self) -> f64
fn read_f64_ne(&mut self) -> f64
Reads a f64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness (little-endian on x86/x64, big-endian on some embedded platforms).
Returns the decoded value and advances the cursor by size_of::<f64>() bytes.
§Panics
Panics if the buffer has fewer than size_of::<f64>() bytes available.
Use the *_checked or try_* variants for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
let value = buf.read_f64_ne();
assert_eq!(buf.remaining(), data.len() - size_of::<f64>()); // Cursor advancedSourcefn read_f64_ne_checked(&mut self) -> Option<f64>
fn read_f64_ne_checked(&mut self) -> Option<f64>
Reads a f64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_f64_ne.
Returns Some(value) and advances the cursor on success, or None if insufficient data.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
if let Some(value) = buf.read_f64_ne_checked() {
// Cursor advanced by size_of::<f64>()
} else {
// Not enough data, cursor unchanged
}Sourcefn try_read_f64_ne(&mut self) -> Result<f64, TryReadError>
fn try_read_f64_ne(&mut self) -> Result<f64, TryReadError>
Reads a f64 value from the buffer in native-endian byte order and advances the cursor.
The byte order depends on the target platform’s endianness.
This is the non-panicking version of read_f64_ne.
Returns Ok(value) and advances the cursor on success, or Err(TryReadError)
with details about requested vs available bytes.
§Examples
use bufkit::Buf;
let data = [147, 23, 89, 201, 156, 74, 33, 198, 67, 142, 91, 205, 38, 177, 124, 59, 183, 96, 241, 167, 82, 135, 49, 213];
let mut buf = &data[..];
match buf.try_read_f64_ne() {
Ok(value) => {
// Cursor advanced by size_of::<f64>()
},
Err(e) => {
// e contains details about requested vs available bytes
}
}Sourcefn peek_u8(&self) -> u8
fn peek_u8(&self) -> u8
Peeks a u8 value from the buffer without advancing the internal cursor.
Returns the first byte from the buffer without consuming it. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer is empty.
Use peek_u8_checked for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [42, 1, 2, 3];
let buf = &data[..];
assert_eq!(buf.peek_u8(), 42);
assert_eq!(buf.remaining(), 4); // UnchangedSourcefn peek_u8_checked(&self) -> Option<u8>
fn peek_u8_checked(&self) -> Option<u8>
Peeks a u8 value from the buffer without advancing the internal cursor.
This is the non-panicking version of peek_u8.
Returns Some(byte) if data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [42];
let buf = &data[..];
assert_eq!(buf.peek_u8_checked(), Some(42));
let empty_buf = &[][..];
assert_eq!(empty_buf.peek_u8_checked(), None);Sourcefn try_peek_u8(&self) -> Result<u8, TryPeekError>
fn try_peek_u8(&self) -> Result<u8, TryPeekError>
Peeks a u8 value from the buffer without advancing the internal cursor.
This is the non-panicking version of peek_u8.
Returns Ok(byte) if data is available, otherwise returns Err.
§Examples
use bufkit::Buf;
let data = [42];
let buf = &data[..];
assert_eq!(buf.peek_u8_checked(), Some(42));
let empty_buf = &[][..];
assert!(empty_buf.try_peek_u8().is_err());Sourcefn read_u8(&mut self) -> u8
fn read_u8(&mut self) -> u8
Reads a u8 value from the buffer and advances the internal cursor.
Returns the first byte from the buffer and advances the cursor by 1 byte.
§Panics
Panics if the buffer is empty.
Use read_u8_checked for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [42, 1, 2, 3];
let mut buf = &data[..];
assert_eq!(buf.read_u8(), 42);
assert_eq!(buf.remaining(), 3); // Cursor advancedSourcefn read_u8_checked(&mut self) -> Option<u8>
fn read_u8_checked(&mut self) -> Option<u8>
Reads a u8 value from the buffer and advances the internal cursor.
This is the non-panicking version of read_u8.
Returns Some(byte) and advances the cursor on success, or None if the buffer is empty.
§Examples
use bufkit::Buf;
let data = [42];
let mut buf = &data[..];
assert_eq!(buf.read_u8_checked(), Some(42));
assert_eq!(buf.remaining(), 0);
assert_eq!(buf.read_u8_checked(), None); // Empty nowSourcefn try_read_u8(&mut self) -> Result<u8, TryReadError>
fn try_read_u8(&mut self) -> Result<u8, TryReadError>
Reads a u8 value from the buffer and advances the internal cursor.
This is the non-panicking version of read_u8.
Returns Ok(byte) and advances the cursor on success, or Err if the buffer is empty.
§Examples
use bufkit::Buf;
let data = [42];
let mut buf = &data[..];
assert_eq!(buf.read_u8_checked(), Some(42));
assert_eq!(buf.remaining(), 0);
assert!(buf.try_read_u8().is_err()); // Empty nowSourcefn peek_i8(&self) -> i8
fn peek_i8(&self) -> i8
Peeks an i8 value from the buffer without advancing the internal cursor.
Returns the first byte from the buffer as a signed integer without consuming it. The buffer position remains unchanged after this operation.
§Panics
Panics if the buffer is empty.
Use peek_i8_checked for non-panicking peeks.
§Examples
use bufkit::Buf;
let data = [255u8, 1, 2, 3]; // 255 as i8 is -1
let buf = &data[..];
assert_eq!(buf.peek_i8(), -1);
assert_eq!(buf.remaining(), 4); // UnchangedSourcefn peek_i8_checked(&self) -> Option<i8>
fn peek_i8_checked(&self) -> Option<i8>
Peeks an i8 value from the buffer without advancing the internal cursor.
This is the non-panicking version of peek_i8.
Returns Some(byte) if data is available, otherwise returns None.
§Examples
use bufkit::Buf;
let data = [255u8]; // -1 as i8
let buf = &data[..];
assert_eq!(buf.peek_i8_checked(), Some(-1));
let empty_buf = &[][..];
assert_eq!(empty_buf.peek_i8_checked(), None);Sourcefn try_peek_i8(&self) -> Result<i8, TryPeekError>
fn try_peek_i8(&self) -> Result<i8, TryPeekError>
Peeks an i8 value from the buffer without advancing the internal cursor.
This is the non-panicking version of peek_i8.
Returns Ok(byte) if data is available, otherwise returns Err.
§Examples
use bufkit::Buf;
let data = [255u8]; // -1 as i8
let buf = &data[..];
assert_eq!(buf.try_peek_i8(), Ok(-1));
let empty_buf = &[][..];
assert!(empty_buf.try_peek_i8().is_err());Sourcefn read_i8(&mut self) -> i8
fn read_i8(&mut self) -> i8
Reads an i8 value from the buffer and advances the internal cursor.
Returns the first byte from the buffer as a signed integer and advances the cursor by 1 byte.
§Panics
Panics if the buffer is empty.
Use read_i8_checked for non-panicking reads.
§Examples
use bufkit::Buf;
let data = [255u8, 1, 2, 3]; // 255 as i8 is -1
let mut buf = &data[..];
assert_eq!(buf.read_i8(), -1);
assert_eq!(buf.remaining(), 3); // Cursor advancedSourcefn read_i8_checked(&mut self) -> Option<i8>
fn read_i8_checked(&mut self) -> Option<i8>
Reads an i8 value from the buffer and advances the internal cursor.
This is the non-panicking version of read_i8.
Returns Some(byte) and advances the cursor on success, or None if the buffer is empty.
§Examples
use bufkit::Buf;
let data = [255u8]; // -1 as i8
let mut buf = &data[..];
assert_eq!(buf.read_i8_checked(), Some(-1));
assert_eq!(buf.remaining(), 0);
assert_eq!(buf.read_i8_checked(), None); // Empty nowSourcefn try_read_i8(&mut self) -> Result<i8, TryReadError>
fn try_read_i8(&mut self) -> Result<i8, TryReadError>
Reads an i8 value from the buffer and advances the internal cursor.
This is the non-panicking version of read_i8.
Returns Ok(byte) and advances the cursor on success, or Err(Try ReadError) if the buffer is empty.
§Examples
use bufkit::Buf;
let data = [255u8]; // -1 as i8
let mut buf = &data[..];
assert_eq!(buf.try_read_i8(), Ok(-1));
assert_eq!(buf.remaining(), 0);
assert!(buf.try_read_i8().is_err()); // Empty nowSourcefn to_vec(&self) -> Vec<u8> ⓘ
Available on crate features std or alloc only.
fn to_vec(&self) -> Vec<u8> ⓘ
std or alloc only.Converts the read buffer to a Vec<u8> instance.
Creates a new vector containing a copy of all available bytes in the buffer. The original buffer remains unchanged.
§Examples
use bufkit::Buf;
let data = [1, 2, 3, 4, 5];
let buf = &data[..];
let vec = buf.to_vec();
assert_eq!(vec, vec![1, 2, 3, 4, 5]);Sourcefn to_bytes(&self) -> Bytes
Available on crate feature bytes_1 and (crate features std or alloc) only.
fn to_bytes(&self) -> Bytes
bytes_1 and (crate features std or alloc) only.Converts the read buffer to a Bytes instance.
Creates a new Bytes instance containing a copy of all available bytes in the buffer.
The original buffer remains unchanged.
Sourcefn to_bytes_mut(&self) -> BytesMut
Available on crate feature bytes_1 and (crate features std or alloc) only.
fn to_bytes_mut(&self) -> BytesMut
bytes_1 and (crate features std or alloc) only.Converts the read buffer to a BytesMut instance.
Creates a new BytesMut instance containing a copy of all available bytes in the buffer.
The original buffer remains unchanged.
Implementations on Foreign Types§
Source§impl Buf for &[u8]
impl Buf for &[u8]
fn remaining(&self) -> usize
fn has_remaining(&self) -> bool
fn advance(&mut self, cnt: usize)
fn try_advance(&mut self, cnt: usize) -> Result<(), TryAdvanceError>
fn truncate(&mut self, len: usize)
fn segment(&self, range: impl RangeBounds<usize>) -> Self
fn try_segment( &self, range: impl RangeBounds<usize>, ) -> Result<Self, TrySegmentError>
fn split_off(&mut self, at: usize) -> Self
fn split_off_checked(&mut self, at: usize) -> Option<Self>
fn split_to(&mut self, at: usize) -> Self
fn split_to_checked(&mut self, at: usize) -> Option<Self>
fn try_split_off(&mut self, at: usize) -> Result<Self, OutOfBounds>
fn try_split_to(&mut self, at: usize) -> Result<Self, OutOfBounds>
fn buffer(&self) -> &[u8] ⓘ
fn buffer_from(&self, offset: usize) -> &[u8] ⓘ
fn buffer_from_checked(&self, offset: usize) -> Option<&[u8]>
Source§impl Buf for Bytes
impl Buf for Bytes
fn remaining(&self) -> usize
fn has_remaining(&self) -> bool
fn buffer(&self) -> &[u8] ⓘ
fn buffer_from(&self, offset: usize) -> &[u8] ⓘ
fn buffer_from_checked(&self, offset: usize) -> Option<&[u8]>
fn advance(&mut self, cnt: usize)
fn truncate(&mut self, len: usize)
fn segment(&self, range: impl RangeBounds<usize>) -> Self
fn split_off(&mut self, at: usize) -> Self
fn split_to(&mut self, at: usize) -> Self
fn read_u8(&mut self) -> u8
fn read_u8_checked(&mut self) -> Option<u8>
fn try_read_u8(&mut self) -> Result<u8, TryReadError>
fn read_i8(&mut self) -> i8
fn read_i8_checked(&mut self) -> Option<i8>
fn try_read_i8(&mut self) -> Result<i8, TryReadError>
Source§fn to_bytes(&self) -> Bytes
fn to_bytes(&self) -> Bytes
bytes_1 and (crate features std or alloc) only.