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
use std::alloc::Layout;
use opaque_pool::{DropPolicy, OpaquePool};
// Using a specific layout.
let layout = Layout::new::<u32>();
let pool = OpaquePool::builder().layout(layout).build();
// Using type-based layout.
let pool = OpaquePool::builder().layout_of::<u64>().build();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();Sourcepub fn build(self) -> OpaquePool
pub fn build(self) -> OpaquePool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OpaquePoolBuilder
impl RefUnwindSafe for OpaquePoolBuilder
impl Send for OpaquePoolBuilder
impl Sync for OpaquePoolBuilder
impl Unpin for OpaquePoolBuilder
impl UnwindSafe for OpaquePoolBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more