BytesView

Struct BytesView 

Source
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 BytesBuf to build the byte sequence piece by piece, consuming the buffered data as a new BytesView when finished.
  • Clone an existing BytesView with clone().
  • Take a range of bytes from an existing BytesView via range().
  • Combine multiple BytesView instances into one via from_views(), concat() or append().
  • Copy data from a &[u8] using copied_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

Source

pub fn to_bytes(&self) -> Bytes

Available on crate features 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

Source

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.

Source

pub fn from_views<I>(views: I) -> Self
where I: IntoIterator<Item = Self>, <I as IntoIterator>::IntoIter: DoubleEndedIterator,

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.

Source

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.

Source

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);
Source

pub fn is_empty(&self) -> bool

Whether the view is of a zero-sized byte sequence.

Source

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).

Source

pub fn range<R>(&self, range: R) -> Self
where 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.

Source

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.

Source

pub fn consume_all_slices<F>(&mut self, f: F)
where F: FnMut(&[u8]),

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());
Source

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");
Source

pub fn io_slices<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize

Fills an array with IoSlices representing this view.

Returns the number of elements written into dst. If there is not enough space in dst to represent the entire view, only as many slices as fit will be written.

See also slices() for a version that fills an array of regular slices instead of IoSlices.

§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 std::io::IoSlice;

use bytesbuf::BytesView;

let view = BytesView::from_views([part1, part2]);

let mut io_slices = [IoSlice::new(&[]); 4];
let count = view.io_slices(&mut io_slices);

for i in 0..count {
    println!(
        "IoSlice {i}: {} bytes at {:p}",
        io_slices[i].len(),
        io_slices[i].as_ptr()
    );
}
Source

pub fn slices<'a>(&'a self, dst: &mut [&'a [u8]]) -> usize

Fills an array with byte slices representing this view.

Returns the number of elements written into dst. If there is not enough space in dst to represent the entire view, only as many slices as fit will be written.

See also io_slices() for a version that fills an array of IoSlices instead of regular byte slices.

§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]);

let mut slices: [&[u8]; 4] = [&[]; 4];
let count = view.slices(&mut slices);

for i in 0..count {
    println!(
        "Slice {i}: {} bytes at {:p}",
        slices[i].len(),
        slices[i].as_ptr()
    );
}
Source

pub fn first_slice_meta(&self) -> Option<&dyn Any>

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.

Source

pub fn iter_slice_metas(&self) -> BytesViewSliceMetas<'_>

Iterates over the metadata of all the slices that make up the view.

Each slice iterated over is a slice that would be returned by first_slice() at some point during the complete consumption of the data covered by a BytesView.

You may wish to iterate over the metadata to determine in advance which implementation strategy to use for a function, depending on what the metadata indicates about the configuration of the memory blocks backing the byte sequence.

§Example
use bytesbuf::BytesView;

let view = BytesView::copied_from_slice(b"Hello", &memory);

let all_page_aligned = view
    .iter_slice_metas()
    .all(|meta| meta.is_some_and(|m| m.is::<PageAlignedMemory>()));

if all_page_aligned {
    println!("All slices are page-aligned, using optimized I/O path.");
}

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.

Source

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.

Source

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.

Source

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

pub fn as_read(&mut self) -> impl Read

Exposes the instance through the Read trait.

§Example
use std::io::Read;

use bytesbuf::BytesView;

let mut view = BytesView::copied_from_slice(b"Hello, world!", &memory);
let mut reader = view.as_read();

let mut buffer = [0u8; 5];
let bytes_read = reader.read(&mut buffer)?;

assert_eq!(bytes_read, 5);
assert_eq!(&buffer, b"Hello");
Source§

impl BytesView

Source

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.

Source

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.

Source

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.

Source

pub fn get_num_le<T: FromBytes>(&mut self) -> T
where T::Bytes: Sized,

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.

Source

pub fn get_num_be<T: FromBytes>(&mut self) -> T
where T::Bytes: Sized,

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.

Source

pub fn get_num_ne<T: FromBytes>(&mut self) -> T
where T::Bytes: Sized,

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.
Source§

fn remaining(&self) -> usize

Returns the number of bytes between the current position and the end of the buffer. Read more
Source§

fn chunk(&self) -> &[u8]

Returns a slice starting at the current position and of length between 0 and Buf::remaining(). Note that this can return a shorter slice (this allows non-continuous internal representation). Read more
Source§

fn chunks_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize

Available on crate feature std only.
Fills dst with potentially multiple slices starting at self’s current position. Read more
Source§

fn advance(&mut self, cnt: usize)

Advance the internal cursor of the Buf Read more
Source§

fn has_remaining(&self) -> bool

Returns true if there are any more bytes to consume Read more
Source§

fn copy_to_slice(&mut self, dst: &mut [u8])

Copies bytes from self into dst. Read more
Source§

fn get_u8(&mut self) -> u8

Gets an unsigned 8 bit integer from self. Read more
Source§

fn get_i8(&mut self) -> i8

Gets a signed 8 bit integer from self. Read more
Source§

fn get_u16(&mut self) -> u16

Gets an unsigned 16 bit integer from self in big-endian byte order. Read more
Source§

fn get_u16_le(&mut self) -> u16

Gets an unsigned 16 bit integer from self in little-endian byte order. Read more
Source§

fn get_u16_ne(&mut self) -> u16

Gets an unsigned 16 bit integer from self in native-endian byte order. Read more
Source§

fn get_i16(&mut self) -> i16

Gets a signed 16 bit integer from self in big-endian byte order. Read more
Source§

fn get_i16_le(&mut self) -> i16

Gets a signed 16 bit integer from self in little-endian byte order. Read more
Source§

fn get_i16_ne(&mut self) -> i16

Gets a signed 16 bit integer from self in native-endian byte order. Read more
Source§

fn get_u32(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the big-endian byte order. Read more
Source§

fn get_u32_le(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the little-endian byte order. Read more
Source§

fn get_u32_ne(&mut self) -> u32

Gets an unsigned 32 bit integer from self in native-endian byte order. Read more
Source§

fn get_i32(&mut self) -> i32

Gets a signed 32 bit integer from self in big-endian byte order. Read more
Source§

fn get_i32_le(&mut self) -> i32

Gets a signed 32 bit integer from self in little-endian byte order. Read more
Source§

fn get_i32_ne(&mut self) -> i32

Gets a signed 32 bit integer from self in native-endian byte order. Read more
Source§

fn get_u64(&mut self) -> u64

Gets an unsigned 64 bit integer from self in big-endian byte order. Read more
Source§

fn get_u64_le(&mut self) -> u64

Gets an unsigned 64 bit integer from self in little-endian byte order. Read more
Source§

fn get_u64_ne(&mut self) -> u64

Gets an unsigned 64 bit integer from self in native-endian byte order. Read more
Source§

fn get_i64(&mut self) -> i64

Gets a signed 64 bit integer from self in big-endian byte order. Read more
Source§

fn get_i64_le(&mut self) -> i64

Gets a signed 64 bit integer from self in little-endian byte order. Read more
Source§

fn get_i64_ne(&mut self) -> i64

Gets a signed 64 bit integer from self in native-endian byte order. Read more
Source§

fn get_u128(&mut self) -> u128

Gets an unsigned 128 bit integer from self in big-endian byte order. Read more
Source§

fn get_u128_le(&mut self) -> u128

Gets an unsigned 128 bit integer from self in little-endian byte order. Read more
Source§

fn get_u128_ne(&mut self) -> u128

Gets an unsigned 128 bit integer from self in native-endian byte order. Read more
Source§

fn get_i128(&mut self) -> i128

Gets a signed 128 bit integer from self in big-endian byte order. Read more
Source§

fn get_i128_le(&mut self) -> i128

Gets a signed 128 bit integer from self in little-endian byte order. Read more
Source§

fn get_i128_ne(&mut self) -> i128

Gets a signed 128 bit integer from self in native-endian byte order. Read more
Source§

fn get_uint(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in big-endian byte order. Read more
Source§

fn get_uint_le(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in little-endian byte order. Read more
Source§

fn get_uint_ne(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in native-endian byte order. Read more
Source§

fn get_int(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in big-endian byte order. Read more
Source§

fn get_int_le(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in little-endian byte order. Read more
Source§

fn get_int_ne(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in native-endian byte order. Read more
Source§

fn get_f32(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn get_f32_le(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn get_f32_ne(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn get_f64(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn get_f64_le(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn get_f64_ne(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn try_copy_to_slice(&mut self, dst: &mut [u8]) -> Result<(), TryGetError>

Copies bytes from self into dst. Read more
Source§

fn try_get_u8(&mut self) -> Result<u8, TryGetError>

Gets an unsigned 8 bit integer from self. Read more
Source§

fn try_get_i8(&mut self) -> Result<i8, TryGetError>

Gets a signed 8 bit integer from self. Read more
Source§

fn try_get_u16(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u16_le(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u16_ne(&mut self) -> Result<u16, TryGetError>

Gets an unsigned 16 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i16(&mut self) -> Result<i16, TryGetError>

Gets a signed 16 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i16_le(&mut self) -> Result<i16, TryGetError>

Gets an signed 16 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i16_ne(&mut self) -> Result<i16, TryGetError>

Gets a signed 16 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u32(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u32_le(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u32_ne(&mut self) -> Result<u32, TryGetError>

Gets an unsigned 32 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i32(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i32_le(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i32_ne(&mut self) -> Result<i32, TryGetError>

Gets a signed 32 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u64(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u64_le(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u64_ne(&mut self) -> Result<u64, TryGetError>

Gets an unsigned 64 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i64(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i64_le(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i64_ne(&mut self) -> Result<i64, TryGetError>

Gets a signed 64 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_u128(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_u128_le(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_u128_ne(&mut self) -> Result<u128, TryGetError>

Gets an unsigned 128 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_i128(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in big-endian byte order. Read more
Source§

fn try_get_i128_le(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in little-endian byte order. Read more
Source§

fn try_get_i128_ne(&mut self) -> Result<i128, TryGetError>

Gets a signed 128 bit integer from self in native-endian byte order. Read more
Source§

fn try_get_uint(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in big-endian byte order. Read more
Source§

fn try_get_uint_le(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in little-endian byte order. Read more
Source§

fn try_get_uint_ne(&mut self, nbytes: usize) -> Result<u64, TryGetError>

Gets an unsigned n-byte integer from self in native-endian byte order. Read more
Source§

fn try_get_int(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in big-endian byte order. Read more
Source§

fn try_get_int_le(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in little-endian byte order. Read more
Source§

fn try_get_int_ne(&mut self, nbytes: usize) -> Result<i64, TryGetError>

Gets a signed n-byte integer from self in native-endian byte order. Read more
Source§

fn try_get_f32(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn try_get_f32_le(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn try_get_f32_ne(&mut self) -> Result<f32, TryGetError>

Gets an IEEE754 single-precision (4 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn try_get_f64(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in big-endian byte order. Read more
Source§

fn try_get_f64_le(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in little-endian byte order. Read more
Source§

fn try_get_f64_ne(&mut self) -> Result<f64, TryGetError>

Gets an IEEE754 double-precision (8 bytes) floating point number from self in native-endian byte order. Read more
Source§

fn copy_to_bytes(&mut self, len: usize) -> Bytes

Consumes len bytes inside self and returns new instance of Bytes with this data. Read more
Source§

fn take(self, limit: usize) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from self. Read more
Source§

fn chain<U>(self, next: U) -> Chain<Self, U>
where U: Buf, Self: Sized,

Creates an adaptor which will chain this buffer with another. Read more
Source§

fn reader(self) -> Reader<Self>
where Self: Sized,

Available on crate feature std only.
Creates an adaptor which implements the Read trait for self. Read more
Source§

impl Clone for BytesView

Source§

fn clone(&self) -> BytesView

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BytesView

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BytesView

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Bytes> for BytesView

Available on crate features bytes-compat only.
Source§

fn from(value: Bytes) -> Self

Converts a Bytes instance into a BytesView.

This operation is always zero-copy, though does cost a small dynamic allocation.

Source§

impl From<BytesView> for BytesBuf

Source§

fn from(value: BytesView) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for BytesView

Source§

fn from(value: Vec<u8>) -> Self

Converts a Vec<u8> instance into a BytesView.

This operation is always zero-copy, though does cost a small dynamic allocation.

Source§

impl PartialEq<&[u8]> for BytesView

Source§

fn eq(&self, other: &&[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const LEN: usize> PartialEq<&[u8; LEN]> for BytesView

Source§

fn eq(&self, other: &&[u8; LEN]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<BytesView> for &[u8]

Source§

fn eq(&self, other: &BytesView) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const LEN: usize> PartialEq<BytesView> for &[u8; LEN]

Source§

fn eq(&self, other: &BytesView) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for BytesView

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.