next_web_common/error/
json_object_error.rs

1
2/// 定义 `JsonObject` 操作中可能出现的错误类型。
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub enum JsonObjectError {
5    /// 键为空。
6    KeyIsEmpty,
7    /// 键已存在。
8    KeyAlreadyExists,
9    /// 值为 `null`。
10    ValueIsNull,
11    /// 键或值为 `null`。
12    KeyOrValueIsNull,
13    /// 解析错误。
14    PaseError,
15}
16
17impl std::fmt::Display for JsonObjectError {
18    /// 格式化错误信息。
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            JsonObjectError::KeyIsEmpty => write!(f, "Key is empty"),
22            JsonObjectError::KeyAlreadyExists => write!(f, "Key already exists"),
23            JsonObjectError::ValueIsNull => write!(f, "Value is null"),
24            JsonObjectError::KeyOrValueIsNull => write!(f, "Key or value is null"),
25            JsonObjectError::PaseError => write!(f, "Parse error"),
26        }
27    }
28}
29
30impl std::error::Error for JsonObjectError {}