Skip to main content

ToJsonExt

Trait ToJsonExt 

Source
pub trait ToJsonExt: ToJson {
    // Provided methods
    fn to_fixed_buf<const N: usize>(&self) -> Option<FixedBuf<N>> { ... }
    fn json_write_reuse<'a>(&self, buf: &'a mut Vec<u8>) -> &'a [u8]  { ... }
    fn json_write_io(&self, w: impl Write) -> Result<()> { ... }
}
Expand description

Extension trait adding stack-buffer and reuse helpers for every T: ToJson.

Provided Methods§

Source

fn to_fixed_buf<const N: usize>(&self) -> Option<FixedBuf<N>>

Serialize into a stack-allocated FixedBuf<N>. Returns None if output exceeds N.

Source

fn json_write_reuse<'a>(&self, buf: &'a mut Vec<u8>) -> &'a [u8]

Serialize to a pre-allocated Vec<u8>, clearing it first (amortizes allocation).

Source

fn json_write_io(&self, w: impl Write) -> Result<()>

Serialize to any io::Write.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: ToJson + ?Sized> ToJsonExt for T