pub struct RawJson { /* private fields */ }
Expand description
A validated JSON string slice.
Implementations§
Methods from Deref<Target = MaybeJson>§
Sourcepub fn parse<'a, T: FromJson<'a>>(&'a self) -> Result<T, JsonError>
pub fn parse<'a, T: FromJson<'a>>(&'a self) -> Result<T, JsonError>
Examples found in repository?
examples/cookbook.rs (line 25)
5fn deferred_parsing() -> Res<()> {
6 #[derive(Jsony, Debug)]
7 #[jsony(Json)]
8 struct Alpha<'a> {
9 value: &'a str,
10 lazy: &'a RawJson,
11 }
12
13 let input = jsony::object! {
14 value: "Hello",
15 lazy: {
16 key: true,
17 numbers: [1, 2, 3],
18 nested: {
19 data: 42
20 }
21 }
22 };
23
24 let alpha: Alpha = jsony::from_json(&input)?;
25 assert_eq!(alpha.lazy["nested"]["data"].parse::<u32>()?, 42);
26
27 let output = jsony::to_json(&alpha);
28
29 assert_eq!(input, output.as_str());
30
31 Ok(())
32}
pub fn json_error(&self) -> Option<JsonError>
pub fn decode_error(&self) -> Option<&'static DecodeError>
Sourcepub fn key_error(&self) -> Option<&'static str>
pub fn key_error(&self) -> Option<&'static str>
If the value is currently a MissingObjectKey get the key that causes error is possible.
pub fn is_error(&self) -> bool
Trait Implementations§
Source§impl FromJson<'_> for Box<RawJson>
impl FromJson<'_> for Box<RawJson>
Source§fn decode_json(parser: &mut Parser<'_>) -> Result<Self, &'static DecodeError>
fn decode_json(parser: &mut Parser<'_>) -> Result<Self, &'static DecodeError>
Decodes a JSON value from the parser. Read more
Source§unsafe fn emplace_from_json(
dest: NonNull<()>,
parser: &mut Parser<'a>,
) -> Result<(), &'static DecodeError>
unsafe fn emplace_from_json( dest: NonNull<()>, parser: &mut Parser<'a>, ) -> Result<(), &'static DecodeError>
Parses a JSON value and writes it directly to the given memory location.
If Ok(()) is returned
dest
is guaranteed to be initialized Read moreSource§impl<'de> FromJson<'de> for &'de RawJson
impl<'de> FromJson<'de> for &'de RawJson
Source§fn decode_json(parser: &mut Parser<'de>) -> Result<Self, &'static DecodeError>
fn decode_json(parser: &mut Parser<'de>) -> Result<Self, &'static DecodeError>
Decodes a JSON value from the parser. Read more
Source§unsafe fn emplace_from_json(
dest: NonNull<()>,
parser: &mut Parser<'a>,
) -> Result<(), &'static DecodeError>
unsafe fn emplace_from_json( dest: NonNull<()>, parser: &mut Parser<'a>, ) -> Result<(), &'static DecodeError>
Parses a JSON value and writes it directly to the given memory location.
If Ok(()) is returned
dest
is guaranteed to be initialized Read moreSource§impl ToJson for RawJson
impl ToJson for RawJson
Source§fn encode_json__jsony(&self, output: &mut TextWriter<'_>) -> Self::Kind
fn encode_json__jsony(&self, output: &mut TextWriter<'_>) -> Self::Kind
Converts
self
to JSON and appends it to the given TextWriter
.
Note: this method is prefixed to avoid collisions in macros that
that invoke it via method resolution.