litl-val 0.2.0

A memory efficient representation of JSON values
Documentation
use super::{slim_boxed_slice::SlimBoxedString, tiny_string::TinyString};

pub enum KeyE {
    ShortString(TinyString),
    LongString(SlimBoxedString),
}

impl KeyE {
    #[inline]
    pub fn string(s: String) -> Self {
        if let Ok(s) = TinyString::try_from(s.as_str()) {
            KeyE::ShortString(s)
        } else {
            KeyE::LongString(SlimBoxedString::from_string(s))
        }
    }

    #[inline]
    pub fn str(s: &str) -> Self {
        if let Ok(s) = TinyString::try_from(s) {
            KeyE::ShortString(s)
        } else {
            KeyE::LongString(SlimBoxedString::from_str(s))
        }
    }
}