Struct RawJson

Source
pub struct RawJson { /* private fields */ }
Expand description

A validated JSON string slice.

Implementations§

Source§

impl RawJson

Source

pub fn as_str(&self) -> &str

Methods from Deref<Target = MaybeJson>§

Source

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}
Source

pub fn json_error(&self) -> Option<JsonError>

Source

pub fn decode_error(&self) -> Option<&'static DecodeError>

Source

pub fn key_error(&self) -> Option<&'static str>

If the value is currently a MissingObjectKey get the key that causes error is possible.

Source

pub fn is_error(&self) -> bool

Trait Implementations§

Source§

impl Debug for RawJson

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for RawJson

Source§

type Target = MaybeJson

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl FromJson<'_> for Box<RawJson>

Source§

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>

Parses a JSON value and writes it directly to the given memory location. If Ok(()) is returned dest is guaranteed to be initialized Read more
Source§

impl<'de> FromJson<'de> for &'de RawJson

Source§

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>

Parses a JSON value and writes it directly to the given memory location. If Ok(()) is returned dest is guaranteed to be initialized Read more
Source§

impl ToJson for RawJson

Source§

type Kind = AnyValue

Represents the kind of JSON value that will be produced. Read more
Source§

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.