1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pub use simd_json_derive_int::*; use std::collections; use std::io::{self, Write}; use value_trait::generator::BaseGenerator; mod impls; pub type Result = io::Result<()>; pub trait Serialize { fn json_write<W>(&self, writer: &mut W) -> Result where W: Write; #[inline] fn json_vec(&self) -> io::Result<Vec<u8>> { let mut v = Vec::with_capacity(512); self.json_write(&mut v)?; Ok(v) } #[inline] fn json_string(&self) -> io::Result<String> { self.json_vec() .map(|v| unsafe { String::from_utf8_unchecked(v) }) } } struct DummyGenerator<W: Write>(W); impl<W: Write> BaseGenerator for DummyGenerator<W> { type T = W; #[inline] fn get_writer(&mut self) -> &mut <Self as BaseGenerator>::T { &mut self.0 } #[inline] fn write_min(&mut self, _: &[u8], _: u8) -> io::Result<()> { unimplemented!() } }