Trait MemConfig

Source
pub trait MemConfig {
    // Required methods
    fn new() -> Self;
    fn debug_assert_config();
    fn capacity(&self, segments: usize) -> usize;
    fn segment_size(&self, segment: usize) -> usize;
    fn segment_and_offset(&self, index: usize) -> (usize, usize);

    // Provided method
    fn update_capacity(&mut self, _segments: usize) { ... }
}
Expand description

Configures the sizes of segments and how to index entries. Linear, Proportional and Exponential implement this trait.

Required Methods§

Source

fn new() -> Self

Source

fn debug_assert_config()

Called by ctors to assert that the configuration is valid.

Some MemConfig implementations may put constraints on (const generic) parameters. Currently it is impossible to assert these at compile time in stable rust. In debug builds we check these constraints when a SegVec uses some config. The three shipped MemConfig implementations check here that the ‘FACTOR’ is not zero.

Source

fn capacity(&self, segments: usize) -> usize

Takes the number of allocated segments, returns the total capacity.

Source

fn segment_size(&self, segment: usize) -> usize

Returns the size of the nth segment (starting at 0).

Source

fn segment_and_offset(&self, index: usize) -> (usize, usize)

Translates a flat index into (segment, offset)

Provided Methods§

Source

fn update_capacity(&mut self, _segments: usize)

Updates the capacity to the given number of segments.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const FACTOR: usize> MemConfig for Exponential<FACTOR>

Source§

impl<const FACTOR: usize> MemConfig for Linear<FACTOR>

Source§

impl<const FACTOR: usize> MemConfig for Proportional<FACTOR>