pub struct BytesView { /* private fields */ }Expand description
A view over a sequence of immutable bytes.
Only the contents are immutable - the view itself can be mutated in terms of progressively marking the byte sequence as consumed until the view becomes empty.
§Creating a BytesView
Instances can be created in different ways:
- Use a
BytesBufto build the byte sequence piece by piece, consuming the buffered data as a newBytesViewwhen finished. - Clone an existing
BytesViewwithclone(). - Take a range of bytes from an existing
BytesViewviarange(). - Combine multiple
BytesViewinstances into one viafrom_views(),concat()orappend(). - Copy data from a
&[u8]usingcopied_from_slice().
Some of these methods may require you to first obtain access to a memory provider.
§Memory layout
A byte sequence represented by bytesbuf types may consist of any number
of separate byte slices, each of which contains one or more bytes of data.
There is no upper or lower bound on the length of each slice of bytes. At one extreme, a byte sequence may be entirely represented by a single slice of bytes. At the opposite extreme, it is legal for each byte to be represented by a separate non-consecutive slice.
Examples of legal memory layouts for the byte sequence b'Hello':
['H', 'e', 'l', 'l', 'o']['H', 'e'], ['l', 'l', 'o']['H'], ['e'], ['l'], ['l'], ['o']
Code using these APIs is required to work with any memory layout, as there are no guarantees on which layout will be used for which byte sequences.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"Hello!", &memory);
// Read bytes one at a time until the view is empty.
while !view.is_empty() {
let byte = view.get_byte();
println!("Read byte: {byte}");
}
assert!(view.is_empty());Implementations§
Source§impl BytesView
impl BytesView
Sourcepub fn to_bytes(&self) -> Bytes
Available on crate features bytes-compat only.
pub fn to_bytes(&self) -> Bytes
bytes-compat only.Returns a bytes::Bytes that contains the same byte sequence.
§Example
use bytes::Buf;
use bytesbuf::BytesView;
let view = BytesView::copied_from_slice(b"\x12\x34\x56\x78", &memory);
let mut bytes = view.to_bytes();
// Consume the data using the bytes crate's Buf trait.
assert_eq!(bytes.get_u16(), 0x1234);
assert_eq!(bytes.get_u16(), 0x5678);
assert!(!bytes.has_remaining());§Performance
This operation is zero-copy if the sequence is backed by a single consecutive slice of memory capacity.
If the sequence is backed by multiple slices of memory capacity, the data will be copied
to a new Bytes instance backed by new memory capacity from the Rust global allocator.
You generally want to avoid this conversion in performance-sensitive code.
This conversion always requires a small dynamic memory allocation for metadata, so avoiding conversions is valuable even if zero-copy.
§Why is this not .into()?
We do not allow conversion via .into() because the conversion is not guaranteed to be
a cheap operation and may involve data copying. The .to_bytes() function must always
be explicitly called to make the conversion more obvious and easier to catch in reviews.
Source§impl BytesView
impl BytesView
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a view over a zero-sized byte sequence.
Use a BytesBuf to create a view over some actual data.
Sourcepub fn from_views<I>(views: I) -> Self
pub fn from_views<I>(views: I) -> Self
Concatenates a number of existing byte sequences, yielding a combined view.
§Example
use bytesbuf::BytesView;
let header = BytesView::copied_from_slice(b"HTTP/1.1 ", &memory);
let status = BytesView::copied_from_slice(b"200 ", &memory);
let message = BytesView::copied_from_slice(b"OK", &memory);
let response_line = BytesView::from_views([header, status, message]);
assert_eq!(response_line.len(), 15);
assert_eq!(response_line, b"HTTP/1.1 200 OK");§Panics
Panics if the resulting view would be larger than usize::MAX bytes.
Sourcepub fn copied_from_slice(bytes: &[u8], memory: &impl Memory) -> Self
pub fn copied_from_slice(bytes: &[u8], memory: &impl Memory) -> Self
Creates a BytesView by copying the contents of a &[u8].
§Example
use bytesbuf::BytesView;
const CONTENT_TYPE_KEY: &[u8] = b"Content-Type: ";
let header_key = BytesView::copied_from_slice(CONTENT_TYPE_KEY, &tcp_connection.memory());
assert_eq!(header_key.len(), 14);§Reusing without copying
There is intentionally no mechanism in the bytesbuf crate to reference an existing
&[u8] without copying the contents, even if it has a 'static lifetime.
The purpose of this limitation is to discourage accidentally involving arbitrary
memory in high-performance I/O workflows. For efficient I/O processing, data must
be stored in memory configured according to the needs of the consuming I/O endpoint,
which is not the case for an arbitrary &'static [u8].
To reuse memory allocations, you need to reuse BytesView instances themselves.
See the bb_reuse.rs example in the bytesbuf crate for a detailed example.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of bytes exposed through the view.
Consuming bytes from the view reduces its length.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"Hello", &memory);
assert_eq!(view.len(), 5);
_ = view.get_byte();
assert_eq!(view.len(), 4);
_ = view.get_num_le::<u16>();
assert_eq!(view.len(), 2);Sourcepub fn extend_lifetime(&self) -> MemoryGuard
pub fn extend_lifetime(&self) -> MemoryGuard
Extends the lifetime of the memory capacity backing this view.
This can be useful when unsafe code is used to reference the contents of a BytesView and it
is possible to reach a condition where the BytesView itself no longer exists, even though
the contents are referenced (e.g. because the remaining references are in non-Rust code).
Sourcepub fn range<R>(&self, range: R) -> Selfwhere
R: RangeBounds<usize>,
pub fn range<R>(&self, range: R) -> Selfwhere
R: RangeBounds<usize>,
Returns a range of the byte sequence.
The bounds logic only considers data currently present in the view. Any data already consumed is not considered part of the view.
§Example
use bytesbuf::BytesView;
let view = BytesView::copied_from_slice(b"Hello, world!", &memory);
assert_eq!(view.range(0..5), b"Hello");
assert_eq!(view.range(7..), b"world!");
assert_eq!(view.range(..5), b"Hello");
assert_eq!(view.range(..), b"Hello, world!");§Panics
Panics if the provided range is outside the bounds of the view.
Sourcepub fn range_checked<R>(&self, range: R) -> Option<Self>where
R: RangeBounds<usize>,
pub fn range_checked<R>(&self, range: R) -> Option<Self>where
R: RangeBounds<usize>,
Returns a range of the byte sequence or None if out of bounds.
The bounds logic only considers data currently present in the view. Any data already consumed is not considered part of the view.
Sourcepub fn consume_all_slices<F>(&mut self, f: F)
pub fn consume_all_slices<F>(&mut self, f: F)
Executes a function f on each slice, consuming them all.
The slices that make up the view are iterated in order,
providing each to f. The view becomes empty after this.
§Example
use bytesbuf::BytesView;
// Create a multi-slice view by concatenating independent views.
let mut view = BytesView::from_views([part1, part2, part3]);
view.consume_all_slices(|slice| {
println!("Slice of {} bytes: {:?}", slice.len(), slice);
});
assert!(view.is_empty());Sourcepub fn first_slice(&self) -> &[u8] ⓘ
pub fn first_slice(&self) -> &[u8] ⓘ
References the first slice of bytes in the byte sequence.
Returns an empty slice if the view is over a zero-sized byte sequence.
§Memory layout
A byte sequence represented by bytesbuf types may consist of any number
of separate byte slices, each of which contains one or more bytes of data.
There is no upper or lower bound on the length of each slice of bytes. At one extreme, a byte sequence may be entirely represented by a single slice of bytes. At the opposite extreme, it is legal for each byte to be represented by a separate non-consecutive slice.
Examples of legal memory layouts for the byte sequence b'Hello':
['H', 'e', 'l', 'l', 'o']['H', 'e'], ['l', 'l', 'o']['H'], ['e'], ['l'], ['l'], ['o']
Code using these APIs is required to work with any memory layout, as there are no guarantees on which layout will be used for which byte sequences.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"0123456789ABCDEF", &memory);
// Read the first 10 bytes without assuming the length of first_slice().
let mut ten_bytes = Vec::with_capacity(10);
while ten_bytes.len() < 10 {
let slice = view.first_slice();
let bytes_to_take = slice.len().min(10 - ten_bytes.len());
ten_bytes.extend_from_slice(&slice[..bytes_to_take]);
view.advance(bytes_to_take);
}
assert_eq!(ten_bytes, b"0123456789");Sourcepub fn slices(&self) -> BytesViewSlices<'_> ⓘ
pub fn slices(&self) -> BytesViewSlices<'_> ⓘ
Iterates over all the slices that make up this view, together with their metadata.
Each item is a tuple of (data, meta) where data is a byte slice and meta is the
optional metadata of the memory block backing that slice.
§Memory layout
A byte sequence represented by bytesbuf types may consist of any number
of separate byte slices, each of which contains one or more bytes of data.
There is no upper or lower bound on the length of each slice of bytes. At one extreme, a byte sequence may be entirely represented by a single slice of bytes. At the opposite extreme, it is legal for each byte to be represented by a separate non-consecutive slice.
Examples of legal memory layouts for the byte sequence b'Hello':
['H', 'e', 'l', 'l', 'o']['H', 'e'], ['l', 'l', 'o']['H'], ['e'], ['l'], ['l'], ['o']
Code using these APIs is required to work with any memory layout, as there are no guarantees on which layout will be used for which byte sequences.
§Example
use bytesbuf::BytesView;
let view = BytesView::from_views([part1, part2]);
for (data, meta) in view.slices() {
let is_page_aligned = meta.is_some_and(|m| m.is::<PageAlignedMemory>());
println!(
"Slice of {} bytes (page-aligned: {is_page_aligned})",
data.len()
);
}See the stand-alone example bb_optimal_path.rs in the bytesbuf crate for
a more detailed example of how to make use of the slice metadata.
Sourcepub fn first_slice_meta(&self) -> Option<&dyn BlockMeta>
pub fn first_slice_meta(&self) -> Option<&dyn BlockMeta>
Inspects the metadata of the first_slice().
None if there is no metadata associated with the first slice or
if the view is over a zero-sized byte sequence.
§Example
use bytesbuf::BytesView;
let view = BytesView::copied_from_slice(b"Hello", &memory);
let is_page_aligned = view
.first_slice_meta()
.is_some_and(|meta| meta.is::<PageAlignedMemory>());
println!("First slice is page-aligned: {is_page_aligned}");See the stand-alone example bb_optimal_path.rs in the bytesbuf crate for
a more detailed example of how to make use of the slice metadata.
Sourcepub fn advance(&mut self, count: usize)
pub fn advance(&mut self, count: usize)
Removes the first count bytes from the front of the view.
The consumed bytes are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"0123456789ABCDEF", &memory);
// Read the first 10 bytes without assuming the length of first_slice().
let mut ten_bytes = Vec::with_capacity(10);
while ten_bytes.len() < 10 {
let slice = view.first_slice();
let bytes_to_take = slice.len().min(10 - ten_bytes.len());
ten_bytes.extend_from_slice(&slice[..bytes_to_take]);
view.advance(bytes_to_take);
}
assert_eq!(ten_bytes, b"0123456789");§Panics
Panics if count is greater than the number of bytes remaining.
Sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Appends another view to the end of this one.
This is a zero-copy operation, reusing the memory capacity of the other view.
§Example
use bytesbuf::BytesView;
let mut greeting = BytesView::copied_from_slice(b"Hello, ", &memory);
let name = BytesView::copied_from_slice(b"world!", &memory);
greeting.append(name);
assert_eq!(greeting, b"Hello, world!");§Panics
Panics if the resulting view would be larger than usize::MAX bytes.
Sourcepub fn concat(&self, other: Self) -> Self
pub fn concat(&self, other: Self) -> Self
Returns a new view that concatenates this view with another.
This is a zero-copy operation, reusing the memory capacity of the other view.
§Example
use bytesbuf::BytesView;
let greeting = BytesView::copied_from_slice(b"Hello, ", &memory);
let name = BytesView::copied_from_slice(b"world!", &memory);
let message = greeting.concat(name);
// Original view is unchanged.
assert_eq!(greeting, b"Hello, ");
// New view contains the concatenation.
assert_eq!(message, b"Hello, world!");§Panics
Panics if the resulting view would be larger than usize::MAX bytes.
Source§impl BytesView
impl BytesView
Sourcepub fn get_byte(&mut self) -> u8
pub fn get_byte(&mut self) -> u8
Consumes a u8 from the byte sequence.
The consumed byte is dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"ABC", &memory);
assert_eq!(view.get_byte(), b'A');
assert_eq!(view.get_byte(), b'B');
assert_eq!(view.get_byte(), b'C');
assert!(view.is_empty());§Panics
Panics if the view does not cover enough bytes of data.
Sourcepub fn copy_to_slice(&mut self, dst: &mut [u8])
pub fn copy_to_slice(&mut self, dst: &mut [u8])
Transfers bytes into an initialized slice.
The copied bytes are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"Hello, world!", &memory);
let mut buffer = [0u8; 5];
view.copy_to_slice(&mut buffer);
assert_eq!(&buffer, b"Hello");
assert_eq!(view.len(), 8); // ", world!" remains§Panics
Panics if the destination is larger than the view.
Sourcepub fn copy_to_uninit_slice(&mut self, dst: &mut [MaybeUninit<u8>])
pub fn copy_to_uninit_slice(&mut self, dst: &mut [MaybeUninit<u8>])
Transfers bytes into a potentially uninitialized slice.
The copied bytes are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use std::mem::MaybeUninit;
use bytesbuf::BytesView;
let mut view = BytesView::copied_from_slice(b"Hello", &memory);
let mut buffer: [MaybeUninit<u8>; 5] = [const { MaybeUninit::uninit() }; 5];
view.copy_to_uninit_slice(&mut buffer);
// SAFETY: The buffer has been fully initialized by copy_to_uninit_slice.
let buffer: [u8; 5] = unsafe { std::mem::transmute(buffer) };
assert_eq!(&buffer, b"Hello");§Panics
Panics if the destination is larger than the view.
Sourcepub fn get_num_le<T: FromBytes>(&mut self) -> T
pub fn get_num_le<T: FromBytes>(&mut self) -> T
Consumes a number of type T in little-endian representation.
The bytes of the T are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
// Little-endian: least significant byte first.
let data: &[u8] = &[
0x34, 0x12, // u16: 0x1234
0x78, 0x56, 0x34, 0x12, // u32: 0x12345678
];
let mut view = BytesView::copied_from_slice(data, &memory);
assert_eq!(view.get_num_le::<u16>(), 0x1234);
assert_eq!(view.get_num_le::<u32>(), 0x12345678);
assert!(view.is_empty());§Panics
Panics if the view does not cover enough bytes of data.
Sourcepub fn get_num_be<T: FromBytes>(&mut self) -> T
pub fn get_num_be<T: FromBytes>(&mut self) -> T
Consumes a number of type T in big-endian representation.
The bytes of the T are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
// Big-endian: most significant byte first.
let data: &[u8] = &[
0x12, 0x34, 0x56, 0x78, // u32: 0x12345678
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, // u64: 0x0123456789ABCDEF
];
let mut view = BytesView::copied_from_slice(data, &memory);
assert_eq!(view.get_num_be::<u32>(), 0x12345678);
assert_eq!(view.get_num_be::<u64>(), 0x0123456789ABCDEF);
assert!(view.is_empty());§Panics
Panics if the view does not cover enough bytes of data.
Sourcepub fn get_num_ne<T: FromBytes>(&mut self) -> T
pub fn get_num_ne<T: FromBytes>(&mut self) -> T
Consumes a number of type T in native-endian representation.
The bytes of the T are dropped from the view, moving any remaining bytes to the front.
If permitted by memory layout considerations and reference counts, the memory capacity backing the dropped bytes is released back to the memory provider.
§Example
use bytesbuf::BytesView;
// Native-endian: byte order matches the platform.
let value1: u16 = 0x1234;
let value2: u64 = 0x0123456789ABCDEF;
let mut data = Vec::new();
data.extend_from_slice(&value1.to_ne_bytes());
data.extend_from_slice(&value2.to_ne_bytes());
let mut view = BytesView::copied_from_slice(&data, &memory);
assert_eq!(view.get_num_ne::<u16>(), 0x1234);
assert_eq!(view.get_num_ne::<u64>(), 0x0123456789ABCDEF);
assert!(view.is_empty());§Panics
Panics if the view does not cover enough bytes of data.
Trait Implementations§
Source§impl Buf for BytesView
Available on crate features bytes-compat only.
impl Buf for BytesView
bytes-compat only.Source§fn remaining(&self) -> usize
fn remaining(&self) -> usize
Source§fn chunk(&self) -> &[u8] ⓘ
fn chunk(&self) -> &[u8] ⓘ
Buf::remaining(). Note that this can return a shorter slice (this
allows non-continuous internal representation). Read moreSource§fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize
fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize
std only.Source§fn has_remaining(&self) -> bool
fn has_remaining(&self) -> bool
Source§fn copy_to_slice(&mut self, dst: &mut [u8])
fn copy_to_slice(&mut self, dst: &mut [u8])
Source§fn get_u16(&mut self) -> u16
fn get_u16(&mut self) -> u16
self in big-endian byte order. Read moreSource§fn get_u16_le(&mut self) -> u16
fn get_u16_le(&mut self) -> u16
self in little-endian byte order. Read moreSource§fn get_u16_ne(&mut self) -> u16
fn get_u16_ne(&mut self) -> u16
self in native-endian byte order. Read moreSource§fn get_i16(&mut self) -> i16
fn get_i16(&mut self) -> i16
self in big-endian byte order. Read moreSource§fn get_i16_le(&mut self) -> i16
fn get_i16_le(&mut self) -> i16
self in little-endian byte order. Read moreSource§fn get_i16_ne(&mut self) -> i16
fn get_i16_ne(&mut self) -> i16
self in native-endian byte order. Read moreSource§fn get_u32(&mut self) -> u32
fn get_u32(&mut self) -> u32
self in the big-endian byte order. Read moreSource§fn get_u32_le(&mut self) -> u32
fn get_u32_le(&mut self) -> u32
self in the little-endian byte order. Read moreSource§fn get_u32_ne(&mut self) -> u32
fn get_u32_ne(&mut self) -> u32
self in native-endian byte order. Read moreSource§fn get_i32(&mut self) -> i32
fn get_i32(&mut self) -> i32
self in big-endian byte order. Read moreSource§fn get_i32_le(&mut self) -> i32
fn get_i32_le(&mut self) -> i32
self in little-endian byte order. Read moreSource§fn get_i32_ne(&mut self) -> i32
fn get_i32_ne(&mut self) -> i32
self in native-endian byte order. Read moreSource§fn get_u64(&mut self) -> u64
fn get_u64(&mut self) -> u64
self in big-endian byte order. Read moreSource§fn get_u64_le(&mut self) -> u64
fn get_u64_le(&mut self) -> u64
self in little-endian byte order. Read moreSource§fn get_u64_ne(&mut self) -> u64
fn get_u64_ne(&mut self) -> u64
self in native-endian byte order. Read moreSource§fn get_i64(&mut self) -> i64
fn get_i64(&mut self) -> i64
self in big-endian byte order. Read moreSource§fn get_i64_le(&mut self) -> i64
fn get_i64_le(&mut self) -> i64
self in little-endian byte order. Read moreSource§fn get_i64_ne(&mut self) -> i64
fn get_i64_ne(&mut self) -> i64
self in native-endian byte order. Read moreSource§fn get_u128(&mut self) -> u128
fn get_u128(&mut self) -> u128
self in big-endian byte order. Read moreSource§fn get_u128_le(&mut self) -> u128
fn get_u128_le(&mut self) -> u128
self in little-endian byte order. Read moreSource§fn get_u128_ne(&mut self) -> u128
fn get_u128_ne(&mut self) -> u128
self in native-endian byte order. Read moreSource§fn get_i128(&mut self) -> i128
fn get_i128(&mut self) -> i128
self in big-endian byte order. Read moreSource§fn get_i128_le(&mut self) -> i128
fn get_i128_le(&mut self) -> i128
self in little-endian byte order. Read moreSource§fn get_i128_ne(&mut self) -> i128
fn get_i128_ne(&mut self) -> i128
self in native-endian byte order. Read moreSource§fn get_uint(&mut self, nbytes: usize) -> u64
fn get_uint(&mut self, nbytes: usize) -> u64
self in big-endian byte order. Read moreSource§fn get_uint_le(&mut self, nbytes: usize) -> u64
fn get_uint_le(&mut self, nbytes: usize) -> u64
self in little-endian byte order. Read moreSource§fn get_uint_ne(&mut self, nbytes: usize) -> u64
fn get_uint_ne(&mut self, nbytes: usize) -> u64
self in native-endian byte order. Read moreSource§fn get_int(&mut self, nbytes: usize) -> i64
fn get_int(&mut self, nbytes: usize) -> i64
self in big-endian byte order. Read moreSource§fn get_int_le(&mut self, nbytes: usize) -> i64
fn get_int_le(&mut self, nbytes: usize) -> i64
self in little-endian byte order. Read moreSource§fn get_int_ne(&mut self, nbytes: usize) -> i64
fn get_int_ne(&mut self, nbytes: usize) -> i64
self in native-endian byte order. Read moreSource§fn get_f32(&mut self) -> f32
fn get_f32(&mut self) -> f32
self in big-endian byte order. Read moreSource§fn get_f32_le(&mut self) -> f32
fn get_f32_le(&mut self) -> f32
self in little-endian byte order. Read moreSource§fn get_f32_ne(&mut self) -> f32
fn get_f32_ne(&mut self) -> f32
self in native-endian byte order. Read moreSource§fn get_f64(&mut self) -> f64
fn get_f64(&mut self) -> f64
self in big-endian byte order. Read moreSource§fn get_f64_le(&mut self) -> f64
fn get_f64_le(&mut self) -> f64
self in little-endian byte order. Read moreSource§fn get_f64_ne(&mut self) -> f64
fn get_f64_ne(&mut self) -> f64
self in native-endian byte order. Read moreSource§fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>
fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>
Source§fn try_get_u8(&mut self) -> Result<u8, TryGetError>
fn try_get_u8(&mut self) -> Result<u8, TryGetError>
self. Read moreSource§fn try_get_i8(&mut self) -> Result<i8, TryGetError>
fn try_get_i8(&mut self) -> Result<i8, TryGetError>
self. Read moreSource§fn try_get_u16(&mut self) -> Result<u16, TryGetError>
fn try_get_u16(&mut self) -> Result<u16, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>
fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>
fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i16(&mut self) -> Result<i16, TryGetError>
fn try_get_i16(&mut self) -> Result<i16, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>
fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>
fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u32(&mut self) -> Result<u32, TryGetError>
fn try_get_u32(&mut self) -> Result<u32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>
fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>
fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i32(&mut self) -> Result<i32, TryGetError>
fn try_get_i32(&mut self) -> Result<i32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>
fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>
fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u64(&mut self) -> Result<u64, TryGetError>
fn try_get_u64(&mut self) -> Result<u64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>
fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>
fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i64(&mut self) -> Result<i64, TryGetError>
fn try_get_i64(&mut self) -> Result<i64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>
fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>
fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_u128(&mut self) -> Result<u128, TryGetError>
fn try_get_u128(&mut self) -> Result<u128, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>
fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>
fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_i128(&mut self) -> Result<i128, TryGetError>
fn try_get_i128(&mut self) -> Result<i128, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>
fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>
fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>
fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>
fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>
fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>
fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>
fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>
fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_f32(&mut self) -> Result<f32, TryGetError>
fn try_get_f32(&mut self) -> Result<f32, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>
fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>
fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>
self in native-endian byte order. Read moreSource§fn try_get_f64(&mut self) -> Result<f64, TryGetError>
fn try_get_f64(&mut self) -> Result<f64, TryGetError>
self in big-endian byte order. Read moreSource§fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>
fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>
self in little-endian byte order. Read moreSource§fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>
fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>
self in native-endian byte order. Read moreSource§fn copy_to_bytes(&mut self, len: usize) -> Bytes
fn copy_to_bytes(&mut self, len: usize) -> Bytes
Source§impl BufRead for BytesView
Because BytesView is already buffered, it implements BufRead directly
without needing an intermediate buffer. Prefer this over wrapping in std::io::BufReader.
impl BufRead for BytesView
Because BytesView is already buffered, it implements BufRead directly
without needing an intermediate buffer. Prefer this over wrapping in std::io::BufReader.
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read methods, if empty. Read moreSource§fn consume(&mut self, amount: usize)
fn consume(&mut self, amount: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl Read for BytesView
impl Read for BytesView
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more