atomic_arena/
error.rs

1//! Error types.
2
3use std::{error::Error, fmt::Display};
4
5/// Returned when trying to reserve an key on a
6/// full [`Arena`](super::Arena).
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct ArenaFull;
9
10impl Display for ArenaFull {
11	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12		f.write_str("Cannot reserve an key because the arena is full")
13	}
14}
15
16impl Error for ArenaFull {}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19/// An error that can occur when inserting an item
20/// into an [`Arena`](super::Arena) with an existing
21/// [`Key`](super::Key).
22pub enum InsertWithKeyError {
23	/// Cannot insert with this key because it is not reserved.
24	KeyNotReserved,
25	/// Cannot insert with this key because the slot index
26	/// or generation is invalid for this arena.
27	InvalidKey,
28}
29
30impl Display for InsertWithKeyError {
31	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32		match self {
33			InsertWithKeyError::KeyNotReserved => f.write_str("Cannot insert with this key because it is not reserved"),
34			InsertWithKeyError::InvalidKey => f.write_str("Cannot insert with this key because the slot index or generation is invalid for this arena."),
35		}
36	}
37}
38
39impl Error for InsertWithKeyError {}