litl-val 0.2.0

A memory efficient representation of JSON values
Documentation
use ordered_float::NotNan;

use super::{map_ref::MapRef, val::Val};

#[derive(PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
pub enum ValRef<'a> {
    Null,
    Bool(bool),
    Number(NotNan<f64>),
    String(&'a str),
    Array(&'a [Val]),
    Object(MapRef<'a>),
}

impl<'a> ValRef<'a> {
    #[inline]
    pub fn as_str(self) -> Option<&'a str> {
        match self {
            ValRef::String(s) => Some(s),
            _ => None,
        }
    }

    #[inline]
    pub fn get<S: AsRef<str>>(self, key: S) -> Option<&'a Val> {
        match self {
            ValRef::Object(o) => o.get(key),
            _ => None,
        }
    }
}