1use super::MemoryType;
2use core::{fmt, fmt::Display};
3
4#[derive(Debug)]
6#[non_exhaustive]
7pub enum MemoryError {
8 OutOfBoundsAllocation,
10 OutOfBoundsGrowth,
12 OutOfBoundsAccess,
14 InvalidMemoryType,
16 InvalidSubtype {
18 ty: MemoryType,
20 other: MemoryType,
22 },
23 TooManyMemories,
25 InvalidStaticBufferSize,
27}
28
29impl Display for MemoryError {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 match self {
32 Self::OutOfBoundsAllocation => {
33 write!(f, "out of bounds memory allocation")
34 }
35 Self::OutOfBoundsGrowth => {
36 write!(f, "out of bounds memory growth")
37 }
38 Self::OutOfBoundsAccess => {
39 write!(f, "out of bounds memory access")
40 }
41 Self::InvalidMemoryType => {
42 write!(f, "tried to create an invalid virtual memory type")
43 }
44 Self::InvalidSubtype { ty, other } => {
45 write!(f, "memory type {ty:?} is not a subtype of {other:?}",)
46 }
47 Self::TooManyMemories => {
48 write!(f, "too many memories")
49 }
50 Self::InvalidStaticBufferSize => {
51 write!(f, "tried to use too small static buffer")
52 }
53 }
54 }
55}