pub struct JSONEmitter<'w> { /* private fields */ }Expand description
Port of hermes::JSONEmitter (include/hermes/Support/JSONEmitter.h). Emits
JSON to a String. pretty adds newlines + indentation. Unbalanced
dict/array use is caught via debug_assert! (C++ assert).
Strings must be valid UTF-8 (C++ takes StringRef and treats invalid UTF-8
as fatal). Non-ASCII code points are emitted as escaped UTF-16 code units.
Implementations§
Source§impl<'w> JSONEmitter<'w>
impl<'w> JSONEmitter<'w>
pub fn new(out: &'w mut String, pretty: bool) -> JSONEmitter<'w>
pub fn emit_bool(&mut self, val: bool)
pub fn emit_u64(&mut self, val: u64)
Sourcepub fn emit_f64(&mut self, val: f64)
pub fn emit_f64(&mut self, val: f64)
JSONEmitter.cpp:67 — finite via numberToString, non-finite -> “null”.
Sourcepub fn emit_str(&mut self, val: &str)
pub fn emit_str(&mut self, val: &str)
JSONEmitter.cpp:78 — emit a UTF-8 string value (not a dict key).
Sourcepub fn emit_u16(&mut self, val: &[u16])
pub fn emit_u16(&mut self, val: &[u16])
JSONEmitter.cpp:193 — emit a value from UTF-16 code units. Each unit is emitted independently (no surrogate combination).
pub fn emit_null_value(&mut self)
Sourcepub fn emit_key_u16(&mut self, key: &[u16])
pub fn emit_key_u16(&mut self, key: &[u16])
Like emit_key but takes UTF-16 code units (for WTF-8 keys that are not
valid UTF-8). Port-compatible with C++ emitKey -> primitiveEmitString
which decodes WTF-8 and escapes per code unit.