Options

Struct Options 

Source
pub struct Options { /* private fields */ }
Expand description

Options for creating an ARENA

Implementations§

Source§

impl Options

Source

pub const fn with_lock_meta(self, lock_meta: bool) -> Self

Set if lock the meta of the Allocator in the memory to prevent OS from swapping out the header of Allocator. When using memory map backed Allocator, the meta of the Allocator is in the header, meta is frequently accessed, lock (mlock on the header) the meta can reduce the page fault, but yes, this means that one Allocator will have one page are locked in memory, and will not be swapped out. So, this is a trade-off between performance and memory usage.

Default is true.

This configuration has no effect on windows and vec backed Allocator.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_lock_meta(false);
Source

pub const fn with_read(self, read: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option for read access.

This option, when true, will indicate that the file should be read-able if opened.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_read(true);
Source

pub const fn with_write(self, write: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option for write access.

This option, when true, will indicate that the file should be write-able if opened.

If the file already exists, any write calls on it will overwrite its contents, without truncating it.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_write(true);
Source

pub const fn with_append(self, append: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option for the append mode.

This option, when true, means that writes will append to a file instead of overwriting previous contents. Note that setting .write(true).append(true) has the same effect as setting only .append(true).

For most filesystems, the operating system guarantees that all writes are atomic: no writes get mangled because another process writes at the same time.

One maybe obvious note when using append-mode: make sure that all data that belongs together is written to the file in one operation. This can be done by concatenating strings before passing them to write(), or using a buffered writer (with a buffer of adequate size), and calling flush() when the message is complete.

If a file is opened with both read and append access, beware that after opening, and after every write, the position for reading may be set at the end of the file. So, before writing, save the current position (using seek(SeekFrom::Current(opts))), and restore it before the next read.

§Note

This function doesn’t create the file if it doesn’t exist. Use the Options::with_create method to do so.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_append(true);
Source

pub const fn with_truncate(self, truncate: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option for truncating a previous file.

If a file is successfully opened with this option set it will truncate the file to opts length if it already exists.

The file must be opened with write access for truncate to work.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_write(true).with_truncate(true);
Source

pub const fn with_create(self, val: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option to create a new file, or open it if it already exists. If the file does not exist, it is created and set the lenght of the file to the given size.

In order for the file to be created, Options::with_write or Options::with_append access must be used.

See also std::fs::write() for a simple function to create a file with some given data.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_write(true).with_create(true);
Source

pub const fn with_create_new(self, val: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Sets the option to create a new file and set the file length to the given value, failing if it already exists.

No file is allowed to exist at the target location, also no (dangling) symlink. In this way, if the call succeeds, the file returned is guaranteed to be new.

This option is useful because it is atomic. Otherwise between checking whether a file exists and creating a new one, the file may have been created by another process (a TOCTOU race condition / attack).

If .with_create_new(true) is set, .with_create() and .with_truncate() are ignored.

The file must be opened with write or append access in order to create a new file.

§Examples
use rarena_allocator::Options;

let file = Options::new()
  .with_write(true)
  .with_create_new(true);
Source

pub const fn with_offset(self, offset: u64) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Configures the memory map to start at byte offset from the beginning of the file.

This option has no effect on anonymous memory maps or vec backed Allocator.

By default, the offset is 0.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_offset(30);
Source

pub const fn with_stack(self, stack: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Configures the anonymous memory map to be suitable for a process or thread stack.

This option corresponds to the MAP_STACK flag on Linux. It has no effect on Windows.

This option has no effect on file-backed memory maps and vec backed Allocator.

§Example
use rarena_allocator::Options;

let stack = Options::new().with_stack(true);
Source

pub const fn with_huge(self, page_bits: Option<u8>) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Configures the anonymous memory map to be allocated using huge pages.

This option corresponds to the MAP_HUGETLB flag on Linux. It has no effect on Windows.

The size of the requested page can be specified in page bits. If not provided, the system default is requested. The requested length should be a multiple of this, or the mapping will fail.

This option has no effect on file-backed memory maps and vec backed Allocator.

§Example
use rarena_allocator::Options;

let stack = Options::new().with_huge(Some(8));
Source

pub const fn with_populate(self, populate: bool) -> Self

Available on crate feature memmap and non-target_family="wasm" only.

Populate (prefault) page tables for a mapping.

For a file mapping, this causes read-ahead on the file. This will help to reduce blocking on page faults later.

This option corresponds to the MAP_POPULATE flag on Linux. It has no effect on Windows.

This option has no effect on vec backed Allocator.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_populate(true);
Source§

impl Options

Source

pub const fn lock_meta(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Get if lock the meta of the Allocator in the memory to prevent OS from swapping out the header of Allocator. When using memory map backed Allocator, the meta of the Allocator is in the header, meta is frequently accessed, lock (mlock on the header) the meta can reduce the page fault, but yes, this means that one Allocator will have one page are locked in memory, and will not be swapped out. So, this is a trade-off between performance and memory usage.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_lock_meta(false);
assert_eq!(opts.lock_meta(), false);
Source

pub const fn read(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be opened with read access.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_read(true);
assert_eq!(opts.read(), true);
Source

pub const fn write(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be opened with write access.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_write(true);
assert_eq!(opts.write(), true);
Source

pub const fn append(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be opened with append access.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_append(true);
assert_eq!(opts.append(), true);
Source

pub const fn truncate(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be opened with truncate access.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_truncate(true);
assert_eq!(opts.truncate(), true);
Source

pub const fn create(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be created if it does not exist.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_create(true);
assert_eq!(opts.create(), true);
Source

pub const fn create_new(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the file should be created if it does not exist and fail if it does.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_create_new(true);
assert_eq!(opts.create_new(), true);
Source

pub const fn offset(&self) -> u64

Available on crate feature memmap and non-target_family="wasm" only.

Returns the offset of the memory map.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_offset(30);
assert_eq!(opts.offset(), 30);
Source

pub const fn stack(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the memory map should be suitable for a process or thread stack.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_stack(true);
assert_eq!(opts.stack(), true);
Source

pub const fn huge(&self) -> Option<u8>

Available on crate feature memmap and non-target_family="wasm" only.

Returns the page bits of the memory map.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_huge(Some(8));
assert_eq!(opts.huge(), Some(8));
Source

pub const fn populate(&self) -> bool

Available on crate feature memmap and non-target_family="wasm" only.

Returns true if the memory map should populate (prefault) page tables for a mapping.

§Examples
use rarena_allocator::Options;

let opts = Options::new().with_populate(true);
assert_eq!(opts.populate(), true);
Source§

impl Options

Source

pub fn map_anon<A: Allocator>(self) -> Result<A>

Available on crate feature memmap and non-target_family="wasm" only.

Creates a new allocator backed by an anonymous mmap.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};

let arena = Options::new().with_capacity(100).map_anon::<Arena>().unwrap();
Source

pub unsafe fn map<A: Allocator, P: AsRef<Path>>(self, p: P) -> Result<A>

Available on crate feature memmap and non-target_family="wasm" only.

Opens a read only allocator backed by a mmap file.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};





let arena = unsafe { Options::new().with_read(true).map::<Arena, _>(&path,).unwrap() };
Source

pub unsafe fn map_with_path_builder<A: Allocator, PB, E>( self, path_builder: PB, ) -> Result<A, Either<E, Error>>
where PB: FnOnce() -> Result<PathBuf, E>,

Available on crate feature memmap and non-target_family="wasm" only.

Opens a read only allocator backed by a mmap file with the given path builder.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Allocator, Options};





let arena = unsafe { Options::new().with_read(true).map_with_path_builder::<Arena, _, std::io::Error>(|| Ok(path.to_path_buf())).unwrap() };
Source

pub unsafe fn map_copy<A: Allocator, P: AsRef<Path>>(self, path: P) -> Result<A>

Available on crate feature memmap and non-target_family="wasm" only.

Creates a new allocator backed by a copy-on-write memory map backed by a file.

Data written to the allocator will not be visible by other processes, and will not be carried through to the underlying file.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};


let arena = unsafe { Options::new().with_capacity(100).with_read(true).with_write(true).with_create_new(true).map_copy::<Arena, _>(&path,).unwrap() };
Source

pub unsafe fn map_copy_with_path_builder<A: Allocator, PB, E>( self, path_builder: PB, ) -> Result<A, Either<E, Error>>
where PB: FnOnce() -> Result<PathBuf, E>,

Available on crate feature memmap and non-target_family="wasm" only.

Creates a new allocator backed by a copy-on-write memory map backed by a file with the given path builder.

Data written to the allocator will not be visible by other processes, and will not be carried through to the underlying file.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};


let arena = unsafe { Options::new().with_capacity(100).with_create_new(true).with_read(true).with_write(true).map_copy_with_path_builder::<Arena, _, std::io::Error>(|| Ok(path.to_path_buf()),).unwrap() };
Source

pub unsafe fn map_copy_read_only<A: Allocator, P: AsRef<Path>>( self, path: P, ) -> Result<A>

Available on crate feature memmap and non-target_family="wasm" only.

Opens a read only allocator backed by a copy-on-write read-only memory map backed by a file.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};





let arena = unsafe { Options::new().with_read(true).map_copy_read_only::<Arena, _>(&path,).unwrap() };
Source

pub unsafe fn map_copy_read_only_with_path_builder<A: Allocator, PB, E>( self, path_builder: PB, ) -> Result<A, Either<E, Error>>
where PB: FnOnce() -> Result<PathBuf, E>,

Available on crate feature memmap and non-target_family="wasm" only.

Opens a read only allocator backed by a copy-on-write read-only memory map backed by a file with the given path builder.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};





let arena = unsafe {
  Options::new().with_read(true).map_copy_read_only_with_path_builder::<Arena, _, std::io::Error>(|| Ok(path.to_path_buf())).unwrap()
};
Source

pub unsafe fn map_mut<A: Allocator, P: AsRef<Path>>(self, path: P) -> Result<A>

Available on crate feature memmap and non-target_family="wasm" only.

Creates a new allocator backed by a mmap with the given path.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};


let arena = unsafe {
  Options::new()
    .with_capacity(100)
    .with_create_new(true)
    .with_read(true)
    .with_write(true)
    .map_mut::<Arena, _>(&path).unwrap()
};
Source

pub unsafe fn map_mut_with_path_builder<A: Allocator, PB, E>( self, path_builder: PB, ) -> Result<A, Either<E, Error>>
where PB: FnOnce() -> Result<PathBuf, E>,

Available on crate feature memmap and non-target_family="wasm" only.

Creates a new allocator backed by a mmap with the given path builder.

§Safety

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

§Example
use rarena_allocator::{sync::Arena, Options, Allocator};


let arena = unsafe {
  Options::new()
    .with_create_new(true)
    .with_read(true)
    .with_write(true)
    .with_capacity(100)
    .map_mut_with_path_builder::<Arena, _, std::io::Error>(|| Ok(path.to_path_buf())).unwrap()
};
Source§

impl Options

Source

pub const fn new() -> Self

Create an options for creating an ARENA with default values.

Source

pub fn data_offset_unify<A: Allocator>(&self) -> usize

Returns the data offset of the ARENA if the ARENA is in unified memory layout.

See also Options::data_offset.

§Example
use rarena_allocator::{sync, unsync, Options, Allocator};

// Create a sync ARENA.
let opts = Options::new().with_capacity(100);
let data_offset_from_opts = opts.data_offset::<sync::Arena>();
let arena = opts.alloc::<sync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

let data_offset_from_opts = opts.data_offset_unify::<sync::Arena>();
let arena = opts.with_unify(true).alloc::<sync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

// Create a unsync ARENA.
let opts = Options::new().with_capacity(100);
let data_offset_from_opts = opts.data_offset::<unsync::Arena>();
let arena = opts.alloc::<unsync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

let data_offset_from_opts = opts.data_offset_unify::<unsync::Arena>();
let arena = opts.with_unify(true).alloc::<unsync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());
Source

pub fn data_offset<A: Allocator>(&self) -> usize

Returns the data offset of the ARENA if the ARENA is not in unified memory layout.

As the file backed ARENA will only use the unified memory layout and ignore the unify configuration of Options, so see also Options::data_offset_unify, if you want to get the data offset of the ARENA in unified memory layout.

§Example
use rarena_allocator::{sync, unsync, Options, Allocator};

// Create a sync ARENA.
let opts = Options::new().with_capacity(100);
let data_offset_from_opts = opts.data_offset::<sync::Arena>();
let arena = opts.alloc::<sync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

let data_offset_from_opts = opts.data_offset_unify::<sync::Arena>();
let arena = opts.with_unify(true).alloc::<sync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

// Create a unsync ARENA.
let opts = Options::new().with_capacity(100);
let data_offset_from_opts = opts.data_offset::<unsync::Arena>();
let arena = opts.alloc::<unsync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());

let data_offset_from_opts = opts.data_offset_unify::<unsync::Arena>();
let arena = opts.with_unify(true).alloc::<unsync::Arena>().unwrap();
assert_eq!(data_offset_from_opts, arena.data_offset());
Source

pub const fn with_reserved(self, reserved: u32) -> Self

Set the reserved of the ARENA.

The reserved is used to configure the start position of the ARENA. This is useful when you want to add some bytes before the ARENA, e.g. when using the memory map file backed ARENA, you can set the reserved to the size to 8 to store a 8 bytes checksum.

The default reserved is 0.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_reserved(8);
Source

pub const fn with_maximum_alignment(self, alignment: usize) -> Self

Set the maximum alignment of the ARENA.

If you are trying to allocate a T which requires a larger alignment than this value, then will lead to read_unaligned, which is undefined behavior on some platforms.

The alignment must be a power of 2. The default maximum alignment is 8.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_maximum_alignment(16);
Source

pub const fn with_capacity(self, capacity: u32) -> Self

Set the capacity of the ARENA. If the ARENA is backed by a memory map and the original file size is less than the capacity, then the file will be resized to the capacity.

For vec backed ARENA and anonymous memory map backed ARENA, this configuration is required.

For file backed ARENA, this configuration is optional, if the capacity is not set, then the capacity will be the original file size.

The capacity must be greater than the minimum capacity of the ARENA.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_capacity(2048);
Source

pub const fn maybe_capacity(self, capacity: Option<u32>) -> Self

Set or unset the capacity of the ARENA. If the ARENA is backed by a memory map and the original file size is less than the capacity, then the file will be resized to the capacity.

For vec backed ARENA and anonymous memory map backed ARENA, this configuration is required.

For file backed ARENA, this configuration is optional, if the capacity is not set, then the capacity will be the original file size.

The capacity must be greater than the minimum capacity of the ARENA.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_capacity(2048);

/// some business logic
let opts = opts.maybe_capacity(None);
Source

pub const fn with_minimum_segment_size(self, minimum_segment_size: u32) -> Self

Set the minimum segment size of the ARENA.

This value controls the size of the holes.

The default minimum segment size is 48 bytes.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_minimum_segment_size(64);
Source

pub const fn with_maximum_retries(self, maximum_retries: u8) -> Self

Set the maximum retries of the ARENA.

This value controls how many times the ARENA will retry to allocate from slow path.

The default maximum retries is 5.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_maximum_retries(10);
Source

pub const fn with_unify(self, unify: bool) -> Self

Set if use the unify memory layout of the ARENA.

File backed ARENA has different memory layout with other kind backed ARENA, set this value to true will unify the memory layout of the ARENA, which means all kinds of backed ARENA will have the same memory layout.

This value will be ignored if the ARENA is backed by a file backed memory map.

The default value is false.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_unify(true);
Source

pub const fn with_magic_version(self, magic_version: u16) -> Self

Set the external version of the ARENA, this is used by the application using Allocator to ensure that it doesn’t open the Allocator with incompatible data format.

The default value is 0.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_magic_version(1);
Source

pub const fn with_freelist(self, freelist: Freelist) -> Self

Set the freelist configuration for the ARENA. The default freelist is Freelist::Optimistic.

§Example
use rarena_allocator::{Options, Freelist};

let opts = Options::new().with_freelist(Freelist::Pessimistic);
Source

pub const fn reserved(&self) -> u32

Get the reserved of the ARENA.

The reserved is used to configure the start position of the ARENA. This is useful when you want to add some bytes before the ARENA, e.g. when using the memory map file backed ARENA, you can set the reserved to the size to 8 to store a 8 bytes checksum.

The default reserved is 0.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_reserved(8);

assert_eq!(opts.reserved(), 8);
Source

pub const fn maximum_alignment(&self) -> usize

Get the maximum alignment of the ARENA.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_maximum_alignment(16);

assert_eq!(opts.maximum_alignment(), 16);
Source

pub const fn capacity(&self) -> u32

Get the capacity of the ARENA.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_capacity(2048);

assert_eq!(opts.capacity(), 2048);
Source

pub const fn minimum_segment_size(&self) -> u32

Get the minimum segment size of the ARENA.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_minimum_segment_size(64);

assert_eq!(opts.minimum_segment_size(), 64);
Source

pub const fn maximum_retries(&self) -> u8

Get the maximum retries of the ARENA. This value controls how many times the ARENA will retry to allocate from slow path.

The default maximum retries is 5.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_maximum_retries(10);

assert_eq!(opts.maximum_retries(), 10);
Source

pub const fn unify(&self) -> bool

Get if use the unify memory layout of the ARENA.

File backed ARENA has different memory layout with other kind backed ARENA, set this value to true will unify the memory layout of the ARENA, which means all kinds of backed ARENA will have the same memory layout.

This value will be ignored if the ARENA is backed by a file backed memory map.

The default value is false.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_unify(true);

assert_eq!(opts.unify(), true);
Source

pub const fn magic_version(&self) -> u16

Get the external version of the ARENA, this is used by the application using Allocator to ensure that it doesn’t open the Allocator with incompatible data format.

The default value is 0.

§Example
use rarena_allocator::Options;

let opts = Options::new().with_magic_version(1);

assert_eq!(opts.magic_version(), 1);
Source

pub const fn freelist(&self) -> Freelist

Get the freelist configuration for the ARENA.

§Example
use rarena_allocator::{Options, Freelist};

let opts = Options::new().with_freelist(Freelist::Pessimistic);

assert_eq!(opts.freelist(), Freelist::Pessimistic);
Source§

impl Options

Source

pub fn alloc<A: Allocator>(self) -> Result<A, Error>

Create a new Allocator which is backed by a Vec.

§Example
use rarena_allocator::{sync, unsync, Options};

// Create a sync ARENA.
let arena = Options::new().with_capacity(100).alloc::<sync::Arena>().unwrap();

// Create a unsync ARENA.
let arena = Options::new().with_capacity(100).alloc::<unsync::Arena>().unwrap();

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for Options

Auto Trait Implementations§

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<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

Source§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
Source§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

Source§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more