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
use Layout;
/// Error type for allocation failures.
///
/// This error is returned when an allocation operation fails, typically
/// due to insufficient memory or other resource constraints.
///
/// # Examples
///
/// ```
/// use stack_arena::{BufferArena, Allocator, AllocError};
/// use std::alloc::Layout;
///
/// // Create a BufferArena with a small fixed size
/// let mut arena = BufferArena::with_capacity(4096);
///
/// // First allocation succeeds
/// let layout1 = Layout::from_size_align(4096, 1).unwrap();
/// let ptr1 = unsafe { arena.allocate(layout1) }.unwrap();
///
/// // Second allocation fails due to insufficient space
/// let layout2 = Layout::from_size_align(1, 1).unwrap();
/// let result = unsafe { arena.allocate(layout2) };
/// assert!(result.is_err());
/// assert!(matches!(result, Err(AllocError::CapacityExceeded { requested: 1, remaining: 0 })));
/// ```
///
/// Note: Unlike `BufferArena`, the `StackArena` will automatically allocate new chunks
/// when the current chunk is full, so it rarely returns allocation errors.
///
/// # Implementation
///
/// This error implements the standard `Error` and `Display` traits,
/// allowing it to be used with error handling utilities like `Result`.