Skip to content
CryoCryo home
Stdlibcollections

raw_buffer

import std::collections::raw_buffer; · source

RawBuffer<T, A>

type struct RawBuffer<T, A = GlobalAlloc> {
    ptr:      T*;
    capacity: u64;
    alloc:    A;

    static new() -> RawBuffer<T>;
    static new_in(alloc: A) -> RawBuffer<T, A>;
    ptr(&this) -> T*;
    into_raw(mut this) -> T*;
    capacity(&this) -> u64;
    reserve(mut &this, used: u64, additional: u64, min_capacity: u64) -> Result<(), AllocError>;
    reserve_exact(mut &this, used: u64, additional: u64) -> Result<(), AllocError>;
    shrink_to(mut &this, target: u64) -> void;
    resize(mut &this, new_capacity: u64) -> Result<(), AllocError>;
}

The untyped backing store: a pointer, a capacity, and an allocator, with no notion of how many slots are in use. String keeps its own length beside one of these and passes it in as used when growing. reserve doubles past min_capacity; reserve_exact allocates exactly what is asked. into_raw hands the allocation to the caller and forgets it.

Array deliberately does not use it — RawBuffer puts capacity before length, and Array's layout has to match the T[] fat pointer.

Trait implementations

implement<T, A> trait Drop for struct RawBuffer<T, A>
where A: Allocator

Frees the allocation. Elements are never dropped — the buffer does not know which slots are live — so the owner must drop them first.