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
#[derive(Debug, Eq, PartialEq)]
pub enum AllocatorError {
OutOfMemory,
FailedToMap,
NotSlotsAvailable,
NoCompatibleMemoryTypeFound,
InvalidAlignment,
CantFindChunk,
CantFindBlock,
Internal(String),
}
impl std::fmt::Display for AllocatorError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
AllocatorError::OutOfMemory => {
write!(f, "out of memory")
}
AllocatorError::FailedToMap => {
write!(f, "failed to map memory")
}
AllocatorError::NotSlotsAvailable => {
write!(f, "no free slots available")
}
AllocatorError::NoCompatibleMemoryTypeFound => {
write!(f, "no compatible memory type available")
}
AllocatorError::InvalidAlignment => {
write!(f, "alignment is not a power of 2")
}
AllocatorError::Internal(message) => {
write!(f, "{}", message)
}
AllocatorError::CantFindChunk => {
write!(f, "can't find chunk in chunk list")
}
AllocatorError::CantFindBlock => {
write!(f, "can't find block in block list")
}
}
}
}
impl std::error::Error for AllocatorError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}