pub enum JsonValue<'a> {
Raw(&'a [u8]),
String(&'a str),
Number(&'a [u8]),
Bool(bool),
Null,
Array(LazyArray<'a>),
Object(LazyObject<'a>),
}Expand description
Zero-copy JSON value representation
Variants§
Raw(&'a [u8])
Raw bytes slice (not parsed yet)
String(&'a str)
Parsed string (zero-copy)
Number(&'a [u8])
Number stored as bytes for lazy parsing
Bool(bool)
Boolean value
Null
Null value
Array(LazyArray<'a>)
Array with lazy evaluation
Object(LazyObject<'a>)
Object with lazy evaluation
Implementations§
Source§impl<'a> JsonValue<'a>
impl<'a> JsonValue<'a>
Sourcepub fn as_object(&self) -> Option<&LazyObject<'a>>
pub fn as_object(&self) -> Option<&LazyObject<'a>>
Get value as object
Sourcepub fn parse_raw(&mut self) -> Result<()>
pub fn parse_raw(&mut self) -> Result<()>
Force parse raw bytes into the appropriate structured variant.
Classifies the underlying bytes by their first non-whitespace character
and replaces JsonValue::Raw with the matching typed variant
(Null, Bool, Number, String, Array, or Object). Variants other
than Raw are left unchanged.
Numbers, strings, arrays, and objects keep zero-copy semantics by borrowing
from the original byte slice. Strings containing escape sequences cannot be
represented in JsonValue::String<&str> without allocation and are rejected.
§Errors
Returns Error::InvalidJson when the bytes are empty, contain an
unterminated string, contain an escaped string (zero-copy not possible),
or do not begin with a recognised JSON token.
Returns Error::Utf8 when string contents are not valid UTF-8.
§Examples
use pjson_rs::parser::JsonValue;
let mut v = JsonValue::Raw(b"42");
v.parse_raw().unwrap();
assert_eq!(v.as_i64(), Some(42));
let mut v = JsonValue::Raw(b"\"hello\"");
v.parse_raw().unwrap();
assert_eq!(v.as_str(), Some("hello"));Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for JsonValue<'a>
impl<'a> RefUnwindSafe for JsonValue<'a>
impl<'a> Send for JsonValue<'a>
impl<'a> Sync for JsonValue<'a>
impl<'a> Unpin for JsonValue<'a>
impl<'a> UnsafeUnpin for JsonValue<'a>
impl<'a> UnwindSafe for JsonValue<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more