pub struct JsonChecker<R> { /* private fields */ }
Expand description
The JsonChecker
is a io::Read
adapter, it can be used like a pipe,
reading bytes, checkings those and output the same bytes.
If an error is encountered, a JSON syntax error or an io::Error
it is returned by the io::Read::read
method.
§Safety
An error encountered while reading bytes will invalidate the checker.
§Example: read from a slice
use std::io;
use oxidized_json_checker::JsonChecker;
let text = r#"{"I am": "an object"}"#;
let bytes = text.as_bytes();
let mut checker = JsonChecker::new(bytes);
io::copy(&mut checker, &mut io::sink())?;
checker.finish()?;
Implementations§
Source§impl<R> JsonChecker<R>
impl<R> JsonChecker<R>
Sourcepub fn new(reader: R) -> JsonChecker<R> ⓘ
pub fn new(reader: R) -> JsonChecker<R> ⓘ
Construct a JsonChecker. To continue the process, write to the
JsonCheckerlike a sink, and then call
JsonChecker::finish` to obtain the final result.
Sourcepub fn with_max_depth(reader: R, max_depth: usize) -> JsonChecker<R> ⓘ
pub fn with_max_depth(reader: R, max_depth: usize) -> JsonChecker<R> ⓘ
Construct a JsonChecker
and restrict the level of maximum nesting.
For more information read the JsonChecker::new
documentation.
Sourcepub fn finish(self) -> Result<JsonType, Error>
pub fn finish(self) -> Result<JsonType, Error>
The JsonChecker::finish
method must be called after all of the characters
have been processed.
This function consumes the JsonChecker
and returns Ok(JsonType)
if the
JSON text was accepted and the JSON type guessed.
Sourcepub fn into_inner(self) -> Result<(R, JsonType), Error>
pub fn into_inner(self) -> Result<(R, JsonType), Error>
The JsonChecker::into_inner
does the same as the JsonChecker::finish
method but returns the internal reader along with the JSON type guessed.
Trait Implementations§
Source§impl<R> Debug for JsonChecker<R>
impl<R> Debug for JsonChecker<R>
Source§impl<R: Read> Read for JsonChecker<R>
impl<R: Read> Read for JsonChecker<R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more