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
77
//! Arena-specific error types.
use std::error::Error;
use std::fmt;
use murk_core::FieldId;
/// Errors that can occur during arena operations.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ArenaError {
/// Segment pool is full — no more segments can be allocated.
CapacityExceeded {
/// Number of bytes requested.
requested: usize,
/// Total capacity available across all segments.
capacity: usize,
},
/// A `FieldHandle` from a generation that has been reclaimed.
StaleHandle {
/// The generation encoded in the handle.
handle_generation: u32,
/// The oldest live generation in the arena.
oldest_live: u32,
},
/// A `FieldId` that is not registered in the arena.
UnknownField {
/// The unrecognised field.
field: FieldId,
},
/// Attempted to write a field whose mutability does not permit writes
/// in the current context (e.g. writing a `Static` field after init).
NotWritable {
/// The field that was not writable.
field: FieldId,
},
/// Arena configuration is invalid.
InvalidConfig {
/// What is wrong with the configuration.
reason: String,
},
}
impl fmt::Display for ArenaError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CapacityExceeded {
requested,
capacity,
} => {
write!(
f,
"arena capacity exceeded: requested {requested} bytes, capacity {capacity} bytes"
)
}
Self::StaleHandle {
handle_generation,
oldest_live,
} => {
write!(
f,
"stale handle: generation {handle_generation}, oldest live {oldest_live}"
)
}
Self::UnknownField { field } => {
write!(f, "unknown field: {field}")
}
Self::NotWritable { field } => {
write!(f, "field {field} is not writable in this context")
}
Self::InvalidConfig { reason } => {
write!(f, "invalid arena config: {reason}")
}
}
}
}
impl Error for ArenaError {}