pub fn check_reader<R: Read>(
parser: &Tabnas,
reader: R,
) -> Result<Checked<R>, Json5Error>Expand description
Apply the requireValue rule parse_with applies to a source read
from reader, reading only as far as the answer needs: the leading
whitespace and comments, and the first character after them. With the
option on (the default), an empty source is json5_empty and one of
only whitespace and comments json5_no_value, as parse_with has
them; any other source comes back as a reader that gives every byte
reader gives, the ones read here first, for the parse. A read that
fails, or bytes that are not UTF-8, are the parse’s to report (the
engine’s unreadable): the reader gives them as reader did. A parser
without the option, or without the plugin, reads reader as it is.
A host that parses through a reader source of its own, as dmog does through transduce’s, calls this first in place of reading the document whole for the rule.
let parser = tabnas_json5::make();
let error = tabnas_json5::check_reader(&parser, &b" // only a comment"[..]).err();
assert_eq!(error.map(|e| e.code), Some("json5_no_value".to_string()));
let checked = tabnas_json5::check_reader(&parser, &b"[1, 2,]"[..])?;
assert_eq!(parser.parse_reader(checked)?.to_string(), "[1,2]");