Struct satrs::pool::StaticMemoryPool

source ·
pub struct StaticMemoryPool { /* private fields */ }
Available on crate feature alloc only.
Expand description

Pool implementation providing sub-pools with fixed size memory blocks.

This is a simple memory pool implementation which pre-allocates all subpools using a given pool configuration. After the pre-allocation, no dynamic memory allocation will be performed during run-time. This makes the implementation suitable for real-time applications and embedded environments.

The subpool bucket sizes only denote the maximum possible data size being stored inside them and the pool implementation will still track the size of the data stored inside it. The implementation will generally determine the best fitting subpool for given data to add. Currently, the pool does not support spilling to larger subpools if the closest fitting subpool is full. This might be added in the future.

Transactions with the pool are done using a generic address type. Adding any data to the pool will yield a store address. Modification and read operations are done using a reference to a store address. Deletion will consume the store address.

Implementations§

source§

impl StaticMemoryPool

source

pub fn new(cfg: StaticPoolConfig) -> StaticMemoryPool

Create a new local pool from the given configuration. This function will sanitize the given configuration as well.

Trait Implementations§

source§

impl PoolProvider for StaticMemoryPool

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.
source§

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

source§

impl PoolProviderWithGuards for StaticMemoryPool

source§

fn modify_with_guard(&mut self, addr: PoolAddr) -> PoolRwGuard<'_, Self>

This function behaves like PoolProvider::modify, but consumes the provided address and returns a RAII conformant guard object. Read more
source§

fn read_with_guard(&mut self, addr: PoolAddr) -> PoolGuard<'_, Self>

This function behaves like PoolProvider::read, but consumes the provided address and returns a RAII conformant guard object. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.