pub fn sax_parser() -> SaxParserExpand description
Returns a CPUID-selected SAX parser handle.
The CPUID check is performed once; subsequent calls to
SaxParser::parse dispatch to the best available path without
repeating it.
use asmjson::sax::Sax;
use asmjson::sax_parser;
struct Counter { n: usize }
impl<'a> Sax<'a> for Counter {
type Output = usize;
fn null(&mut self) {}
fn bool_val(&mut self, _: bool) {}
fn number(&mut self, _: &str) {}
fn string(&mut self, _: &str) { self.n += 1; }
fn escaped_string(&mut self, _: &str) { self.n += 1; }
fn key(&mut self, _: &str) {}
fn escaped_key(&mut self, _: &str) {}
fn start_object(&mut self) {}
fn end_object(&mut self) {}
fn start_array(&mut self) {}
fn end_array(&mut self) {}
fn finish(self) -> Option<usize> { Some(self.n) }
}
let parser = sax_parser();
let n = parser.parse(r#"["a","b"]"#, Counter { n: 0 }).unwrap();
assert_eq!(n, 2);