1#![allow(clippy::module_name_repetitions)]
2
3use std::alloc::LayoutError;
4
5use thiserror::Error;
6
7#[derive(Debug, Error, PartialEq, Eq, Clone)]
8pub enum AllocationError {
9 #[error("An arithmetic error occurred.")]
10 ArithmeticError,
11 #[error(transparent)]
12 LayoutError(#[from] LayoutError),
13 #[error("Process ran out of memory.")]
14 OutOfMemory,
15}
16
17#[derive(Debug, Error, PartialEq, Eq, Clone)]
18pub enum DeallocationError {
19 #[error("This allocation's marker is corrupted, either memory corruption occurred, or a pointer not allocated by this crate's alloc was passed to realloc or free.")]
20 CorruptedMarker,
21 #[error("This memory was already freed.")]
22 DoubleFree,
23 #[error("The pointer provided was not properly aligned.")]
24 ImproperAlignment,
25 #[error(transparent)]
26 LayoutError(#[from] LayoutError),
27 #[error("Tried to free a null pointer.")]
28 NullPtr,
29}
30
31#[derive(Debug, Error, PartialEq, Eq, Clone)]
32pub enum ReallocationError {
33 #[error(transparent)]
34 AllocationError(#[from] AllocationError),
35 #[error(transparent)]
36 DeallocationError(#[from] DeallocationError),
37 #[error("The pointer provided was not properly aligned.")]
38 ImproperAlignment,
39 #[error("The pointer provided points to already freed memory.")]
40 MarkerFree,
41 #[error("The pointer provided has a corrupted marker, was it allocated by this crate?")]
42 MarkerCorrupted,
43 #[error("The new allocation failed, but your old pointer remains valid.")]
45 NewAllocationFailed(*mut u8),
46}