Struct json::decoder::Decoder
[−]
[src]
pub struct Decoder<I: Iterator> { /* fields omitted */ }
JSON decoder over char
iterators.
Methods
impl<I: Iterator<Item = char>> Decoder<I>
[src]
fn new(c: Config, i: I) -> Decoder<I>
fn default(i: I) -> Decoder<I>
Create decoder with default Config
.
fn is_end(&mut self) -> bool
Have we exhausted the iterator?
fn into_iter(self) -> I
fn iter_mut(&mut self) -> &mut I
fn from_json<T: FromJson>(&mut self) -> DecodeResult<T>
Generic conversion from JSON to an instance of FromJson
.
fn decode(&mut self) -> DecodeResult<Json>
Decode into Json
AST value.
fn skip(&mut self) -> DecodeResult<()>
Decode as generic Json but ignore the result.
Semantically this method is equivalent to Decoder::decode
but potentially more efficient as it tries to avoid allocating
intermediate values.
fn u8(&mut self) -> DecodeResult<u8>
fn u16(&mut self) -> DecodeResult<u16>
fn u32(&mut self) -> DecodeResult<u32>
fn u64(&mut self) -> DecodeResult<u64>
fn usize(&mut self) -> DecodeResult<usize>
fn i8(&mut self) -> DecodeResult<i8>
fn i16(&mut self) -> DecodeResult<i16>
fn i32(&mut self) -> DecodeResult<i32>
fn i64(&mut self) -> DecodeResult<i64>
fn isize(&mut self) -> DecodeResult<isize>
fn f64(&mut self) -> DecodeResult<f64>
fn null(&mut self) -> DecodeResult<()>
fn bool(&mut self) -> DecodeResult<bool>
fn string(&mut self) -> DecodeResult<String>
fn str(&mut self, b: &mut Utf8Buffer, overflow_err: bool) -> DecodeResult<()>
Decode a JSON string into the given Utf8Buffer
.
If the actual string does not fit into the provided buffer
and overflow_err
is true
, DecodeError::BufferOverflow
is returned immediately. If overflow_err
is false we
continue decoding the string, but the buffer will only
contain as much as fits into it.
fn optional<A, F>(&mut self, f: F) -> DecodeResult<Option<A>> where
F: FnMut(&mut Decoder<I>) -> DecodeResult<A>,
F: FnMut(&mut Decoder<I>) -> DecodeResult<A>,
Decode null
(which is mapped to None
) or some other
JSON value (mapped to Some
).
fn has_more(&mut self) -> DecodeResult<bool>
When parsing JSON arrays and objects this needs to be called in between to check if the array / object end has been reached. E.g.
use json::{Decoder, DecodeResult}; fn foo<I: Iterator<Item=char>>(d: &mut Decoder<I>) -> DecodeResult<Vec<u8>> { d.array()?; let mut v = Vec::new(); while d.has_more()? { v.push(d.u8()?) } Ok(v) }
fn array(&mut self) -> DecodeResult<()>
Begin parsing a JSON array.
Before each element is parsed, Decoder::has_more
needs to be queried.
fn array_iter<A: FromJson>(&mut self) -> DecodeResult<ArrayIter<A, I>>
Create a JSON array iterator to decode a homogenous array.
use json::Decoder; let mut d = Decoder::default("[1,2,3,4]".chars()); let mut v: Vec<u8> = Vec::new(); for i in d.array_iter().unwrap() { v.push(i.unwrap()) }
fn object(&mut self) -> DecodeResult<()>
Begin parsing a JSON object.
Before each key is parsed, Decoder::has_more
needs to be queried.
fn key(&mut self) -> DecodeResult<String>
Decode a JSON object key.
fn key_str(
&mut self,
b: &mut Utf8Buffer,
overflow_err: bool
) -> DecodeResult<()>
&mut self,
b: &mut Utf8Buffer,
overflow_err: bool
) -> DecodeResult<()>
Decode a JSON object key into the given buffer.