pub enum AllocError {
OutOfMemory,
InvalidLayout(Layout),
CapacityExceeded {
requested: usize,
remaining: usize,
},
}
Expand description
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
.
Variants§
Trait Implementations§
Source§impl Debug for AllocError
impl Debug for AllocError
Source§impl Display for AllocError
impl Display for AllocError
Source§impl Error for AllocError
impl Error for AllocError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl PartialEq for AllocError
impl PartialEq for AllocError
impl Eq for AllocError
impl StructuralPartialEq for AllocError
Auto Trait Implementations§
impl Freeze for AllocError
impl RefUnwindSafe for AllocError
impl Send for AllocError
impl Sync for AllocError
impl Unpin for AllocError
impl UnwindSafe for AllocError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more