jsn 0.14.0

A library for querying streaming JSON tokens
Documentation
// The string & number `RawToken` variants borrow from an internal scratch `Vec`, and as such the
// lifetime of this enum is only valid till the next call to `.next()`.
//
// This makes the enum tough to actually use
// (a) It can't be returned from an Iterator because it would mutably borrow the iterator (and
// LendingIterators are not yet a thing).
//
// (b) Returning in it from a regular method is a footgun for all sorts of "can't mutably borrow
// twice" compiler errors (especially without polonius).
//
// All this to say, this type is not fit to expose to the end user.
//
// However, it works very well as an intermediate type we can use to filter & skip tokens without
// allocating
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RawToken<'j> {
    Eof,
    Null,
    Bool(bool),
    String(&'j str),
    ObjectKey(&'j str),
    Number(&'j [u8]),
    ObjectStart,
    ObjectEnd,
    ArrayStart,
    ArrayEnd,
    Comma,
    Colon,
}

impl<'i> RawToken<'i> {
    // Returns `true` if the token is a primitive JSON value (i.e. strings, numbers, booleans and
    // null)
    pub fn is_primitive_value(&self) -> bool {
        matches!(
            self,
            RawToken::String(_) | RawToken::Number(_) | RawToken::Bool(_) | RawToken::Null
        )
    }

    // Returns `true` if the token is a comma, colon, bracket or parenthesis
    pub fn is_separator_token(&self) -> bool {
        matches!(
            self,
            RawToken::Colon
                | RawToken::Comma
                | RawToken::ArrayStart
                | RawToken::ArrayEnd
                | RawToken::ObjectStart
                | RawToken::ObjectEnd
        )
    }
}