Trait reactive_messaging::prelude::OgreAllocator
source · pub trait OgreAllocator<SlotType>: Debug + PartialEq<Self>where
SlotType: Debug,{
// Required methods
fn new() -> Self;
fn alloc_ref(&self) -> Option<(&mut SlotType, u32)>;
fn alloc_with<F>(&self, setter: F) -> Option<(&mut SlotType, u32)>
where F: FnOnce(&mut SlotType);
fn dealloc_ref(&self, slot: &SlotType);
fn dealloc_id(&self, slot_id: u32);
fn id_from_ref(&self, slot: &SlotType) -> u32;
fn ref_from_id(&self, slot_id: u32) -> &mut SlotType;
}Expand description
Dictates how data slots should be acquired and returned for future reuse.
Two APIs are available:
- by ref: offers mutable references upon allocation and requiring them for deallocation
- by id: offers u32 ids, which should be translated to mutable references before usage… from there, freeing might either be done from the id or the mut ref.
Regarding comparisons, the
PartialEqtrait should be implemented so any wrapper types using the allocator can be compared: two allocators are only equal if they share the same exact address.
Required Methods§
sourcefn alloc_ref(&self) -> Option<(&mut SlotType, u32)>
fn alloc_ref(&self) -> Option<(&mut SlotType, u32)>
Returns a (mutable reference, slot_id) to the newly allocated slot or None if the allocator is, currently, out of space
– in which case, a [dealloc_ref()] would remedy the situation.
IMPLEMENTORS: #[inline(always)]
sourcefn alloc_with<F>(&self, setter: F) -> Option<(&mut SlotType, u32)>where
F: FnOnce(&mut SlotType),
fn alloc_with<F>(&self, setter: F) -> Option<(&mut SlotType, u32)>where F: FnOnce(&mut SlotType),
Allocates & sets the data with the provided callback f, which should return a DataType.
Returns a (mutable reference, slot_id) to the newly allocated slot or None if the allocator is, currently, out of space
– in which case, a [dealloc_ref()] would remedy the situation.
IMPLEMENTORS: #[inline(always)]
sourcefn dealloc_ref(&self, slot: &SlotType)
fn dealloc_ref(&self, slot: &SlotType)
Returns the slot for reuse by a subsequent call of [alloc_ref()]
IMPLEMENTORS: #[inline(always)]
sourcefn dealloc_id(&self, slot_id: u32)
fn dealloc_id(&self, slot_id: u32)
IMPLEMENTORS: #[inline(always)]
sourcefn id_from_ref(&self, slot: &SlotType) -> u32
fn id_from_ref(&self, slot: &SlotType) -> u32
returns the position (within the allocator’s pool) that the given slot reference occupies
IMPLEMENTORS: #[inline(always)]
sourcefn ref_from_id(&self, slot_id: u32) -> &mut SlotType
fn ref_from_id(&self, slot_id: u32) -> &mut SlotType
returns a reference to the slot position pointed to by slot_id
IMPLEMENTORS: #[inline(always)]