1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{JsonMap, JsonValue};

/// 自定义对象 [`JsonValue`] 也就是 [`serde_json::Value`]的功能扩展trait
pub trait JsonValueExt {
    /// 将`self`对象转换为一个map option对象
    fn into_map_opt(self) -> Option<JsonMap>;
}

impl JsonValueExt for JsonValue {
    #[inline]
    fn into_map_opt(self) -> Option<JsonMap> {
        if let JsonValue::Object(map) = self {
            Some(map)
        } else {
            None
        }
    }
}