Skip to main content

Params

Struct Params 

Source
#[non_exhaustive]
pub struct Params<'a> { pub min_block: usize, pub growth: (usize, usize), pub geo_count: usize, pub extras: &'a [usize], pub huge_threshold: usize, }
Expand description

Parameters for a size-class scheme, consumed by build_table, build_size2class and SizeClasses::build.

All fields are plain data so the whole thing is usable in const context.

#[non_exhaustive], so a future policy field is a semver-minor addition rather than a breaking one. Construct with Params::new — a const fn, since downstream #[non_exhaustive] rejects struct-literal construction (functional-record-update included), leaving new as the only construction path, and const context needs that path callable. The non-breaking half rests on the fields being pub, not on new’s parameter list: a future pub field would extend the struct but not new’s positional signature, so existing Params::new(..) call sites keep compiling and a consumer opts in with let mut p = Params::new(..); p.new_field = value; — post-construction assignment to a pub field, which works outside this crate and in const context too.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§min_block: usize

The minimum block size and the fundamental small-class alignment. Must be a power of two. Every generated class is a multiple of it – see SizeClasses::class_for’s # Preconditions for what that does and does not guarantee about block addresses.

§growth: (usize, usize)

The geometric growth ratio as (num, den) — each class after the first is round_up(ceil(prev * num / den), min_block), with a minimum step of min_block so two adjacent classes never collide. (5, 4) is the classic mimalloc 1.25× small spacing.

§geo_count: usize

How many classes the geometric progression contributes (starting at min_block).

§extras: &'a [usize]

Explicit extra classes to merge into the geometric run — a strictly increasing list, each entry a multiple of min_block and >= min_block (the builder sorted-merges them). All three preconditions are machine-checked: a non-min_block-multiple entry, an entry below min_block (rejects the degenerate 0 “class”), or a non-strictly-increasing entry panics identically in const evaluation (compile error) and at runtime in build_table. It also checks disjointness from the geometric run at its own chokepoint (the merged table must itself be strictly increasing). build_size2class keeps the same check as defense-in-depth for a hand-built table that bypasses build_table entirely. Typical uses: page-aligned classes, an exact size the geometric run skips, a feature-gated medium tier.

Borrowed rather than owned because this is a no_std, zero-alloc crate; in the usual const PARAMS: Params = Params::new(.., EXTRAS, ..) form 'a resolves to 'static, but nothing requires that.

§huge_threshold: usize

The “huge” policy threshold: SizeClasses::is_huge reports true for a size >= this. Pure bookkeeping for the crate — the consumer decides what “huge” means for its own segment policy (guard pages, eager decommit, …).

Implementations§

Source§

impl<'a> Params<'a>

Source

pub const fn new( min_block: usize, growth: (usize, usize), geo_count: usize, extras: &'a [usize], huge_threshold: usize, ) -> Self

Construct a Params from its component fields.

const fn, so it works in const PARAMS: Params = Params::new(..); — the construction path for a #[non_exhaustive] type.

Trait Implementations§

Source§

impl<'a> Clone for Params<'a>

Source§

fn clone(&self) -> Params<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Params<'a>

Source§

impl<'a> Debug for Params<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Params<'a>

§

impl<'a> RefUnwindSafe for Params<'a>

§

impl<'a> Send for Params<'a>

§

impl<'a> Sync for Params<'a>

§

impl<'a> Unpin for Params<'a>

§

impl<'a> UnsafeUnpin for Params<'a>

§

impl<'a> UnwindSafe for Params<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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>,

Source§

type Error = !

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>,

Source§

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.