flex_alloc/storage/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Backing storage types for collections.

use const_default::ConstDefault;

mod alloc;
mod array;
pub(crate) mod boxed;
mod bytes;
mod inline;
pub(crate) mod insert;
mod spill;
pub(crate) mod utils;

pub use self::{
    alloc::{BufferHeader, FatBuffer, ThinBuffer},
    array::ArrayStorage,
    bytes::ByteStorage,
    inline::{Inline, InlineBuffer},
    spill::SpillStorage,
};

/// Create a new array storage buffer for type `T` and maximum capacity `N`.
pub const fn array_storage<T, const N: usize>() -> ArrayStorage<T, N> {
    ArrayStorage::DEFAULT
}

/// Create a new byte storage buffer for a maximum byte capacity `N`.
pub const fn byte_storage<const N: usize>() -> ByteStorage<u8, N> {
    ByteStorage::DEFAULT
}

/// Create a new byte storage buffer for a maximum byte capacity `N`, with
/// a memory alignment matching type `T`.
pub const fn aligned_byte_storage<T, const N: usize>() -> ByteStorage<T, N> {
    ByteStorage::DEFAULT
}

/// Provide access to the associated data for abstract buffer types.
pub trait RawBuffer: Sized {
    /// The concrete data type.
    type RawData: ?Sized;

    /// Access the data as a readonly pointer.
    fn data_ptr(&self) -> *const Self::RawData;

    /// Access the data as a mutable pointer.
    fn data_ptr_mut(&mut self) -> *mut Self::RawData;
}