litl-val 0.2.0

A memory efficient representation of JSON values
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use super::{key::Key, val::Val};

#[derive(PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
pub struct MapRef<'a>(pub(crate) &'a [(Key, Val)]);

impl<'a> MapRef<'a> {
    #[inline]
    pub fn get<S: AsRef<str>>(self, key: S) -> Option<&'a Val> {
        match self
            .0
            .binary_search_by_key(&key.as_ref(), |entry| entry.0.as_str())
        {
            Ok(pos) => Some(&self.0[pos].1),
            Err(_) => None,
        }
    }
}