Trait WriteBuf

pub unsafe trait WriteBuf

Describe a bytes container, like Vec<u8>.

Represents a contiguous segment of allocated memory, a prefix of which is initialized.

It allows starting from an uninitializes chunk of memory and writing to it, progressively initializing it. No re-allocation typically occur after the initial creation.

The main implementors are:

Safety

An implementation has to keep three promises, because the zstd functions this is handed to write straight through the pointer:

Required Methods

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

Returns the valid data part of this container. Should only cover initialized data.

fn capacity(&self) -> usize

Returns the full capacity of this container. May include uninitialized data.

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

Returns a pointer to the start of the data.

unsafe fn filled_until(&mut self, n: usize)

Indicates that the first n bytes of the container have been written.

Safety

The first n bytes of this buffer must actually have been initialized.

Provided Methods

unsafe fn write_from<F>(&mut self, f: F) -> SafeResult
where
    F: FnOnce(*mut c_void, usize) -> SafeResult,

Call the given closure using the pointer and capacity from self.

The closure returns a parseable code which, if valid, is how many bytes it wrote to self.

Safety

The closure must treat its first argument as pointing to potentially uninitialized memory, and must not read from it. It must have written at least n bytes contiguously from that pointer, where n is the value it returns.

Implementors