Skip to main content

ByteBuffer

Trait ByteBuffer 

Source
pub trait ByteBuffer:
    AsRef<[u8]>
    + Clone
    + Send {
    // Required methods
    fn len(&self) -> usize;
    fn get(&self, at: usize) -> &u8;
    fn slice(&self) -> &[u8] ;
    fn slice_start(&self, start: usize) -> &[u8] ;
    fn slice_end(&self, end: usize) -> &[u8] ;
    fn slice_both(&self, start: usize, end: usize) -> &[u8] ;
    fn split(&self, divide: usize) -> (&[u8], &[u8]);

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Immutable byte buffer trait for read-only access to buffer data. Implemented by both OwnedByteBuffer (immutable, Send+Sync) and ManagedByteBuffer (mutable, Send).

Required Methods§

Source

fn len(&self) -> usize

Returns the length of the current view in bytes.

Source

fn get(&self, at: usize) -> &u8

Get byte at at index. Panics if out of bounds.

Source

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

Get immutable slice of entire buffer.

Source

fn slice_start(&self, start: usize) -> &[u8]

Get immutable slice from start offset to end.

Source

fn slice_end(&self, end: usize) -> &[u8]

Get immutable slice from beginning to end offset.

Source

fn slice_both(&self, start: usize, end: usize) -> &[u8]

Get immutable slice from start to end offset.

Source

fn split(&self, divide: usize) -> (&[u8], &[u8])

Split into two immutable slices at divide point. Returns (left, right).

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if buffer length is zero.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§