Skip to main content

JSONEmitter

Struct JSONEmitter 

Source
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>

Source

pub fn new(out: &'w mut String, pretty: bool) -> JSONEmitter<'w>

Source

pub fn emit_bool(&mut self, val: bool)

Source

pub fn emit_i64(&mut self, val: i64)

Covers the C++ integer overloads (short/int/long/…).

Source

pub fn emit_u64(&mut self, val: u64)

Source

pub fn emit_f64(&mut self, val: f64)

JSONEmitter.cpp:67 — finite via numberToString, non-finite -> “null”.

Source

pub fn emit_str(&mut self, val: &str)

JSONEmitter.cpp:78 — emit a UTF-8 string value (not a dict key).

Source

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).

Source

pub fn emit_null_value(&mut self)

Source

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.

Source

pub fn emit_key(&mut self, key: &str)

JSONEmitter.cpp:88 — emit a dict key.

Source

pub fn open_dict(&mut self)

Source

pub fn close_dict(&mut self)

Source

pub fn open_array(&mut self)

Source

pub fn close_array(&mut self)

Source

pub fn end_jsonl(&mut self)

JSONEmitter.cpp:234 — terminate a JSON Lines record.

Auto Trait Implementations§

§

impl<'w> !UnwindSafe for JSONEmitter<'w>

§

impl<'w> Freeze for JSONEmitter<'w>

§

impl<'w> RefUnwindSafe for JSONEmitter<'w>

§

impl<'w> Send for JSONEmitter<'w>

§

impl<'w> Sync for JSONEmitter<'w>

§

impl<'w> Unpin for JSONEmitter<'w>

§

impl<'w> UnsafeUnpin for JSONEmitter<'w>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.