pub struct OpaquePoolBuilder { /* private fields */ }Expand description
Builder for creating an instance of OpaquePool.
OpaquePool requires the item memory layout to be specified at construction time.
Use either .layout() to provide a specific layout or .layout_of::<T>() to generate
a layout based on the provided type.
The layout is mandatory, whereas other settings are optional.
§Examples
Using a specific layout:
use std::alloc::Layout;
use opaque_pool::OpaquePool;
let layout = Layout::new::<u32>();
let pool = OpaquePool::builder().layout(layout).build();Using type-based layout:
use opaque_pool::OpaquePool;
let pool = OpaquePool::builder().layout_of::<u64>().build();§Thread safety
The builder is thread-mobile (Send) and can be safely transferred between threads,
allowing pool configuration to happen on different threads than where the pool is used.
However, it is not thread-safe (Sync) as it contains mutable configuration state.
Implementations§
Source§impl OpaquePoolBuilder
impl OpaquePoolBuilder
Sourcepub fn layout(self, layout: Layout) -> Self
pub fn layout(self, layout: Layout) -> Self
Sets the memory layout for items stored in the pool.
§Examples
use std::alloc::Layout;
use opaque_pool::OpaquePool;
let layout = Layout::new::<u32>();
let pool = OpaquePool::builder().layout(layout).build();Sourcepub fn layout_of<T>(self) -> Self
pub fn layout_of<T>(self) -> Self
Sets the memory layout for items stored in the pool based on a type.
This is a convenience method that automatically creates the layout for the given type.
§Examples
use opaque_pool::OpaquePool;
let pool = OpaquePool::builder().layout_of::<u64>().build();Sourcepub fn drop_policy(self, policy: DropPolicy) -> Self
pub fn drop_policy(self, policy: DropPolicy) -> Self
Sets the drop policy for the pool. This governs how to treat remaining items in the pool when the pool is dropped.
§Examples
use std::alloc::Layout;
use opaque_pool::{DropPolicy, OpaquePool};
let layout = Layout::new::<u32>();
let pool = OpaquePool::builder()
.layout(layout)
.drop_policy(DropPolicy::MustNotDropItems)
.build();