[][src]Struct toolshed::Arena

pub struct Arena { /* fields omitted */ }

An arena implementation that uses preallocated 64KiB pages for all allocations. If a new allocation were to be pushed over the the boundaries of the page, a new page is internally allocated first, thus this version of the arena can never run out of memory unless the process runs out of heap altogether.

Allocating a type larger than the page size will result in a new heap allocation just for that type separate from the page mechanism.

Methods

impl Arena[src]

pub fn new() -> Self[src]

Create a new arena with a single preallocated 64KiB page.

pub fn alloc<'arena, T: Sized + Copy>(&'arena self, value: T) -> &'arena mut T[src]

Put the value onto the page of the arena and return a reference to it.

pub fn alloc_uninitialized<'arena, T: Sized + Copy>(
    &'arena self
) -> Uninitialized<'arena, T>
[src]

Allocate enough bytes for the type T, then return an Uninitialized pointer to the memory.

pub fn alloc_slice<'arena, T: Copy>(&'arena self, val: &[T]) -> &'arena [T][src]

Allocate a slice of T slice onto the arena and return a reference to it. This is useful when the original slice has an undefined lifetime.

Note: static slices (&'static [T]) can be safely used in place of arena-bound slices without having to go through this method.

pub fn alloc_lazy_slice<'arena, T, I: Iterator<Item = T>>(
    &'arena self,
    vals: I,
    n: usize
) -> &'arena [T]
[src]

Allocate a statically-sized but lazily-generated slice [T] out of an iterator This is useful if you're going to make a slice of something and put it on the arena, but you don't want to make an allocation first just to have something to copy in.

The slice will be at maximum length n, further elements of the iterator ignored and not evaluated. If the iterator yields less than n elements, a shorter slice will simply be returned.

pub fn alloc_vec<'arena, T: Copy>(&'arena self, val: Vec<T>) -> &'arena [T][src]

Put a Vec<T> on the arena without reallocating.

pub fn alloc_cow<'input, 'arena, T>(
    &'arena self,
    vals: Cow<'input, [T]>
) -> &'arena [T] where
    T: Sized + Copy + 'input, 
[src]

Allocate many items at once, avoid allocation for owned values.

pub fn alloc_str<'arena>(&'arena self, val: &str) -> &'arena str[src]

Allocate an &str slice onto the arena and return a reference to it. This is useful when the original slice has an undefined lifetime.

Note: static slices (&'static str) can be safely used in place of arena-bound slices without having to go through this method.

pub fn alloc_nul_term_str<'arena>(&'arena self, val: &str) -> NulTermStr[src]

Allocate an &str slice onto the arena as null terminated C-style string. No checks are performed on the source and whether or not it already contains any nul bytes. While this does not create any memory issues, it assumes that the reader of the source can deal with malformed source.

pub fn alloc_string<'arena>(&'arena self, val: String) -> &'arena str[src]

Pushes the String as it's own page onto the arena and returns a reference to it. This does not copy or reallocate the original String.

Trait Implementations

impl Send for Arena[src]

Akin to CopyCell: Sync is unsafe but Send is totally fine!

Auto Trait Implementations

impl !Sync for Arena

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]