Trait flatbuffers::Allocator

source ·
pub unsafe trait Allocator: DerefMut<Target = [u8]> {
    type Error: Display + Debug;

    // Required methods
    fn grow_downwards(&mut self) -> Result<(), Self::Error>;
    fn len(&self) -> usize;
}
Expand description

Trait to implement custom allocation strategies for FlatBufferBuilder.

An implementation can be used with FlatBufferBuilder::new_in, enabling a custom allocation strategy for the FlatBufferBuilder.

§Safety

The implementation of the allocator must match the defined behavior as described by the comments.

Required Associated Types§

source

type Error: Display + Debug

A type describing allocation failures

Required Methods§

source

fn grow_downwards(&mut self) -> Result<(), Self::Error>

Grows the buffer, with the old contents being moved to the end.

NOTE: While not unsound, an implementation that doesn’t grow the internal buffer will get stuck in an infinite loop.

source

fn len(&self) -> usize

Returns the size of the internal buffer in bytes.

Implementors§