pub fn to_json<I, C>(
    stream_iter: &mut I,
    type_name: &str,
    rti: &ReflectedTypeInfo,
    ctx: &mut C
) -> Result<Option<String>, String>where
    C: TestDeserializeContext,
    I: Iterator<Item = TokenTree>,
Expand description

Converts the next part of the stream into JSON deserializable into an object of type type_name.

If the object is a zero-arg struct, this method will return Ok(Some("null")) without looking at the stream.

Otherwise, it will try to convert the next TokenTree in the stream. If end of stream has been reached, this method returns Ok(None)

The JSON string should be deserializable into an object of type type_name.

Default object syntax:

  • An enum is represented as (enum_variant_snake_case <arg1> <arg2> ..), unless it is a unit enum, in which case it can also be represented as enum_variant_snake_case. Enums can have optional arguments, which should all come at the end.
  • A struct is represented as (<arg1> <arg2> ..), unless it has no arguments, in which case it is represented by the empty string.
  • A vec or tuple is represented as [<elem1> <elem2> ..]
  • None/null is represented as null
  • true (resp. false) is represented as true (resp. false)
  • Strings are represented as "something with quotations".
  • A numeric value like -1 or 1.1 is represented as is.
  • You can delimit arguments and elements using whitespace and/or commas.

ctx will extend and/or override the default syntax.