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
use std::error::Error;
use std::fmt::Display;
use crate::Path;
/// Error types for mutation operations.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum MutationError {
/// The specified path does not exist.
IndexError {
/// The path that could not be found.
path: Path<false>,
},
/// Mutation could not be performed at the specified path.
OperationError {
/// The path where the operation could not be performed.
path: Path<false>,
},
/// Error applying a truncate operation.
#[cfg(feature = "truncate")]
TruncateError {
/// The path where the truncation failed.
path: Path<false>,
/// The actual length of the value being truncated.
actual_len: usize,
/// The requested truncation length.
truncate_len: usize,
},
}
impl Display for MutationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::IndexError { path } => {
write!(f, "path {path} does not exist or is malformed")
}
Self::OperationError { path } => {
write!(f, "operation could not be performed at {path}")
}
#[cfg(feature = "truncate")]
Self::TruncateError {
path,
actual_len,
truncate_len,
} => {
write!(
f,
"cannot truncate at {path}: actual length {actual_len} is less than truncate length {truncate_len}"
)
}
}
}
}
impl Error for MutationError {}