Skip to main content

low_latency_data_structures/spmc/
builder.rs

1use bon::Builder;
2
3use crate::mem::Allocator;
4use crate::mem::global::{GlobalAllocator, GlobalAllocatorOptions};
5
6/// Construction-time options for [`new`](super::new).
7///
8/// Wraps the allocator-specific options so the same `new` signature works for
9/// every [`Allocator`] impl. Use [`Options::builder`] to build one explicitly,
10/// or [`Options::global_mlocked`] for the common global + `mlock` case.
11#[derive(Builder)]
12pub struct Options<A>
13where
14    A: Allocator,
15{
16    pub(crate) alloc: A::Options,
17}
18
19impl Options<GlobalAllocator> {
20    /// Convenience shorthand for the common case: the global allocator with
21    /// `mlock` enabled.
22    pub fn global_mlocked() -> Self {
23        Self {
24            alloc: GlobalAllocatorOptions::builder().mlock(true).build(),
25        }
26    }
27}