flex_alloc/storage/
mod.rs

1//! Backing storage types for collections.
2
3use const_default::ConstDefault;
4
5mod alloc;
6mod array;
7pub(crate) mod boxed;
8mod bytes;
9mod inline;
10pub(crate) mod insert;
11mod spill;
12pub(crate) mod utils;
13
14pub use self::{
15    alloc::{BufferHeader, FatBuffer, ThinBuffer},
16    array::ArrayStorage,
17    bytes::ByteStorage,
18    inline::{Inline, InlineBuffer},
19    spill::SpillStorage,
20};
21
22/// Create a new array storage buffer for type `T` and maximum capacity `N`.
23pub const fn array_storage<T, const N: usize>() -> ArrayStorage<T, N> {
24    ArrayStorage::DEFAULT
25}
26
27/// Create a new byte storage buffer for a maximum byte capacity `N`.
28pub const fn byte_storage<const N: usize>() -> ByteStorage<u8, N> {
29    ByteStorage::DEFAULT
30}
31
32/// Create a new byte storage buffer for a maximum byte capacity `N`, with
33/// a memory alignment matching type `T`.
34pub const fn aligned_byte_storage<T, const N: usize>() -> ByteStorage<T, N> {
35    ByteStorage::DEFAULT
36}
37
38/// Provide access to the associated data for abstract buffer types.
39pub trait RawBuffer: Sized {
40    /// The concrete data type.
41    type RawData: ?Sized;
42
43    /// Access the data as a readonly pointer.
44    fn data_ptr(&self) -> *const Self::RawData;
45
46    /// Access the data as a mutable pointer.
47    fn data_ptr_mut(&mut self) -> *mut Self::RawData;
48}