Trait satrs::pool::PoolProvider

source ·
pub trait PoolProvider {
    // Required methods
    fn add(&mut self, data: &[u8]) -> Result<PoolAddr, PoolError>;
    fn free_element<W: FnMut(&mut [u8])>(
        &mut self,
        len: usize,
        writer: W
    ) -> Result<PoolAddr, PoolError>;
    fn modify<U: FnMut(&mut [u8])>(
        &mut self,
        addr: &PoolAddr,
        updater: U
    ) -> Result<(), PoolError>;
    fn read(&self, addr: &PoolAddr, buf: &mut [u8]) -> Result<usize, PoolError>;
    fn delete(&mut self, addr: PoolAddr) -> Result<(), PoolError>;
    fn has_element_at(&self, addr: &PoolAddr) -> Result<bool, PoolError>;
    fn len_of_data(&self, addr: &PoolAddr) -> Result<usize, PoolError>;

    // Provided method
    fn read_as_vec(&self, addr: &PoolAddr) -> Result<Vec<u8>, PoolError> { ... }
}
Expand description

Generic trait for pool providers which provide memory pools for variable sized data.

It specifies a basic API to Self::add, Self::modify, Self::read and Self::delete data in the store at its core. The API was designed so internal optimizations can be performed more easily and that is is also possible to make the pool structure Sync without the whole pool structure being wrapped inside a lock.

Required Methods§

source

fn add(&mut self, data: &[u8]) -> Result<PoolAddr, PoolError>

Add new data to the pool. The provider should attempt to reserve a memory block with the appropriate size and then copy the given data to the block. Yields a PoolAddr which can be used to access the data stored in the pool

source

fn free_element<W: FnMut(&mut [u8])>( &mut self, len: usize, writer: W ) -> Result<PoolAddr, PoolError>

The provider should attempt to reserve a free memory block with the appropriate size first. It then executes a user-provided closure and passes a mutable reference to that memory block to the closure. This allows the user to write data to the memory block. The function should yield a PoolAddr which can be used to access the data stored in the pool.

source

fn modify<U: FnMut(&mut [u8])>( &mut self, addr: &PoolAddr, updater: U ) -> Result<(), PoolError>

Modify data added previously using a given PoolAddr. The provider should use the store address to determine if a memory block exists for that address. If it does, it should call the user-provided closure and pass a mutable reference to the memory block to the closure. This allows the user to modify the memory block.

source

fn read(&self, addr: &PoolAddr, buf: &mut [u8]) -> Result<usize, PoolError>

The provider should copy the data from the memory block to the user-provided buffer if it exists.

source

fn delete(&mut self, addr: PoolAddr) -> Result<(), PoolError>

Delete data inside the pool given a PoolAddr.

source

fn has_element_at(&self, addr: &PoolAddr) -> Result<bool, PoolError>

source

fn len_of_data(&self, addr: &PoolAddr) -> Result<usize, PoolError>

Retrieve the length of the data at the given store address.

Provided Methods§

source

fn read_as_vec(&self, addr: &PoolAddr) -> Result<Vec<u8>, PoolError>

Available on crate feature alloc only.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl PoolProvider for StaticMemoryPool

Available on crate feature alloc only.