pub trait Buffer {
// Required methods
fn allocate(len: usize) -> Self;
fn as_ptr(this: &Self) -> *const u8;
unsafe fn as_mut_slice(this: &mut Self, len: usize) -> &mut [u8] ⓘ;
fn into_ptr(this: Self) -> NonNull<u8>;
unsafe fn from_ptr(ptr: NonNull<u8>, bytes: usize) -> Self;
}Expand description
A trait wrapping memory management.
This is intended to allow you to bring your own allocator for
OwnedBinaryPayloads.
For an implementation example, see the implementation of this trait
for Vec.
Required Methods§
fn as_ptr(this: &Self) -> *const u8
Sourceunsafe fn as_mut_slice(this: &mut Self, len: usize) -> &mut [u8] ⓘ
unsafe fn as_mut_slice(this: &mut Self, len: usize) -> &mut [u8] ⓘ
Returns a slice view of size elements of the given memory.
§Safety
The caller must not request more elements than are allocated.
Sourcefn into_ptr(this: Self) -> NonNull<u8>
fn into_ptr(this: Self) -> NonNull<u8>
Consumes this ownership and returns a pointer to the start of the arena.
Sourceunsafe fn from_ptr(ptr: NonNull<u8>, bytes: usize) -> Self
unsafe fn from_ptr(ptr: NonNull<u8>, bytes: usize) -> Self
“Adopts” the memory at the given pointer, taking it under management.
Running the operation:
let owner = OwnerType::allocate(bytes);
let ptr = OwnerType::into_ptr(owner);
let owner = unsafe { OwnerType::from_ptr(ptr, bytes) };must be a no-op.
§Safety
The pointer must be valid, and the caller must provide the exact size of the given arena.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".