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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Lock-free arena allocator producing [`bytes::Bytes`] via zero-copy freeze.
//!
//! Write into a [`Buffer`], call [`freeze()`](Buffer::freeze), and get back
//! `Bytes` backed by arena memory. The slot or block returns to the arena
//! when the last `Bytes` reference drops.
//!
//! # Allocator modes
//!
//! - [`FixedArena`]: uniform slot sizes and a simple bitmap claim path.
//! - [`BuddyArena`]: power-of-two blocks for variable-size requests.
//!
//! Both produce the same [`Buffer`] type with identical write and freeze
//! semantics.
//!
//! # Quick start
//!
//! ```
//! use std::num::NonZeroUsize;
//! use arena_alligator::FixedArena;
//! use bytes::BufMut;
//!
//! let arena = FixedArena::builder(
//! NonZeroUsize::new(1024).unwrap(),
//! NonZeroUsize::new(4096).unwrap(),
//! ).build().unwrap();
//!
//! let mut buf = arena.allocate().unwrap();
//! buf.put_slice(b"hello");
//! let bytes = buf.freeze();
//! assert_eq!(&bytes[..], b"hello");
//! ```
//!
//! # Auto-spill
//!
//! Enable [`.auto_spill()`](FixedArenaBuilder::auto_spill) on the builder if
//! you want overflow writes to spill onto the heap instead of panicking. The
//! arena allocation is released as soon as the spill happens.
//!
//! # Frozen slice retention
//!
//! Freezing a buffer transfers ownership of the arena slot (or buddy block)
//! to the returned `Bytes`. Cloning or slicing that `Bytes` shares the
//! reference, so the arena memory stays pinned until every clone and slice is
//! dropped.
//!
//! # Async allocation
//!
//! With the `async-alloc` feature, [`AsyncFixedArena`] and [`AsyncBuddyArena`]
//! provide `allocate_async()` which parks until capacity is available.
pub use ;
pub use ;
pub use Buffer;
pub use ;
pub use ;
pub use ;