Skip to main content

Buf

Trait Buf 

Source
pub unsafe trait Buf: Sized {
    const ALIGN: usize;
Show 13 methods // Required methods fn empty() -> Self; fn as_ptr(&self) -> *const u8; fn as_mut_ptr(&mut self) -> *mut u8; fn as_bytes(&self) -> &[u8]; fn len(&self) -> u32; fn capacity(&self) -> u32; fn resize(&mut self, new_len: u32, fill: u8); fn reserve(&mut self, additional: u32); fn extend_from_slice(&mut self, data: &[u8]); // Provided methods fn is_empty(&self) -> bool { ... } fn align_to(&mut self, align: usize) { ... } fn alloc<U: Flat>(&mut self) -> Pos { ... } fn expose_provenance(&self) { ... }
}
Expand description

Backing storage for a Region.

§Safety

Implementors must guarantee:

  • as_ptr() / as_mut_ptr() return pointers valid for len() bytes
  • Buffer base is aligned to at least ALIGN bytes
  • resize zero-fills new bytes [old_len..new_len) and preserves alignment

Required Associated Constants§

Source

const ALIGN: usize

Buffer alignment guarantee.

Required Methods§

Source

fn empty() -> Self

Create an empty buffer (len = 0).

Source

fn as_ptr(&self) -> *const u8

Raw pointer to the buffer start.

Source

fn as_mut_ptr(&mut self) -> *mut u8

Mutable raw pointer to the buffer start.

Source

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

View the buffer contents as a byte slice.

Source

fn len(&self) -> u32

Current byte length.

Source

fn capacity(&self) -> u32

Current capacity in bytes.

Source

fn resize(&mut self, new_len: u32, fill: u8)

Grow or shrink the buffer, filling new bytes with fill.

Source

fn reserve(&mut self, additional: u32)

Ensure at least additional bytes of spare capacity.

Source

fn extend_from_slice(&mut self, data: &[u8])

Append bytes from a slice.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the buffer contains no bytes.

Source

fn align_to(&mut self, align: usize)

Pad len up to the next multiple of align.

Source

fn alloc<U: Flat>(&mut self) -> Pos

Align + allocate space for one U, return its position.

§Compile-time invariant

align_of::<U>() <= ALIGN — the buffer base is aligned to ALIGN (at least 8), so any position that is a multiple of align_of::<U>() yields a correctly aligned absolute address.

Source

fn expose_provenance(&self)

Expose provenance so Near::get can recover it via with_exposed_provenance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Buf for AlignedBuf<T>

Available on crate feature alloc only.
Source§

const ALIGN: usize = Self::BUF_ALIGN

Source§

impl<const N: usize> Buf for FixedBuf<N>

Source§

const ALIGN: usize = 8