pub struct StringSink<'a> { /* private fields */ }Expand description
JsonWrite sink that appends to a String. Infallible.
Implementations§
Trait Implementations§
Source§impl<'a> Debug for StringSink<'a>
impl<'a> Debug for StringSink<'a>
Source§impl JsonWrite for StringSink<'_>
Available on crate feature alloc only.
impl JsonWrite for StringSink<'_>
Available on crate feature
alloc only.Source§type Error = Error
type Error = Error
StringSink widens its error to Error (rather than
core::convert::Infallible) so the float path has a typed
variant for non-finite inputs. The byte/string/integer writes
never fail in practice; only write_float_f64 produces an Err.
Source§fn write_escaped_str(&mut self, s: &str) -> Result<(), Self::Error>
fn write_escaped_str(&mut self, s: &str) -> Result<(), Self::Error>
Literal-run fast path: scan for the next byte that needs escaping,
bulk-append the safe stretch, then emit one escape and resume.
Mirrors the decode_escapes strategy in de.rs in reverse.
Source§fn write_float_f64(&mut self, f: f64) -> Result<(), Self::Error>
fn write_float_f64(&mut self, f: f64) -> Result<(), Self::Error>
Production float path. Currently dispatches to the write!-based
formatter — see the float module below for the alternate ryu
path and the bench that picks between them. Both reject non-finite
inputs with ErrorKind::NonFiniteFloat.
Source§fn write_byte(&mut self, b: u8) -> Result<(), Self::Error>
fn write_byte(&mut self, b: u8) -> Result<(), Self::Error>
Append a single ASCII byte. Used for structural punctuation
(
{, }, [, ], ,, :, ").Source§fn write_str_raw(&mut self, s: &str) -> Result<(), Self::Error>
fn write_str_raw(&mut self, s: &str) -> Result<(), Self::Error>
Append a
&str verbatim. Caller is responsible for any escaping
— this is the structural / pre-escaped path. For user string
payloads, call Self::write_escaped_str instead.Source§fn reserve_hint(&mut self, _additional: usize)
fn reserve_hint(&mut self, _additional: usize)
Source§unsafe fn write_byte_unchecked(&mut self, b: u8) -> Result<(), Self::Error>
unsafe fn write_byte_unchecked(&mut self, b: u8) -> Result<(), Self::Error>
Append a single ASCII byte WITHOUT a per-write capacity check. Read more
Source§fn write_raw_bytes(&mut self, b: &[u8]) -> Result<(), Self::Error>
fn write_raw_bytes(&mut self, b: &[u8]) -> Result<(), Self::Error>
Append a byte slice whose contents are known-valid UTF-8. Read more
Source§fn write_int_i64(&mut self, n: i64) -> Result<(), Self::Error>
fn write_int_i64(&mut self, n: i64) -> Result<(), Self::Error>
Write a signed 64-bit integer as a JSON number.
Source§fn write_int_u64(&mut self, n: u64) -> Result<(), Self::Error>
fn write_int_u64(&mut self, n: u64) -> Result<(), Self::Error>
Write an unsigned 64-bit integer as a JSON number.
Source§fn write_int_i128(&mut self, n: i128) -> Result<(), Self::Error>
fn write_int_i128(&mut self, n: i128) -> Result<(), Self::Error>
Write a signed 128-bit integer as a JSON number.
Source§fn write_int_u128(&mut self, n: u128) -> Result<(), Self::Error>
fn write_int_u128(&mut self, n: u128) -> Result<(), Self::Error>
Write an unsigned 128-bit integer as a JSON number.
Source§unsafe fn write_float_f64_unchecked(
&mut self,
f: f64,
) -> Result<(), Self::Error>
unsafe fn write_float_f64_unchecked( &mut self, f: f64, ) -> Result<(), Self::Error>
Write a finite
f64 ASSUMING the caller has reserved at least
f64::MAX_SERIALIZED_LEN (32) bytes of sink capacity. Skips the
per-call cap check in Vec::extend_from_slice — the second-largest
mispredict source after the comma Vec::push. Read moreSource§unsafe fn write_float_f64_unchecked_finite(
&mut self,
f: f64,
) -> Result<(), Self::Error>
unsafe fn write_float_f64_unchecked_finite( &mut self, f: f64, ) -> Result<(), Self::Error>
Like
write_float_f64_unchecked, but additionally requires the
caller to have validated that f is finite. The per-element
finiteness branch in the bench’s hot loop was the dominant
remaining mispredict source after the cap-check elimination;
hoisting validation to a one-shot pre-scan over the whole slice
removes that branch from the inner loop entirely. Read moreSource§unsafe fn write_float_f64_taint(&mut self, f: f64) -> Result<(), Self::Error>
unsafe fn write_float_f64_taint(&mut self, f: f64) -> Result<(), Self::Error>
Per-element float write that branchlessly tolerates non-finite
input. Tainted bytes (junk ASCII for non-finite values) land in
the sink; the caller is expected to query the sink’s
take_nonfinite_taint() once at the end of the slice and turn a
non-zero result into a typed error. Read moreSource§fn take_nonfinite_taint(&mut self) -> u64
fn take_nonfinite_taint(&mut self) -> u64
Read and clear the accumulated non-finite taint from the sink.
Returns 0 for sinks without taint tracking. The array writer
queries this once after a batch of
write_float_f64_taint
calls; a non-zero result means at least one input was inf/NaN
and the call must return Err(NonFiniteFloat).Auto Trait Implementations§
impl<'a> !UnwindSafe for StringSink<'a>
impl<'a> Freeze for StringSink<'a>
impl<'a> RefUnwindSafe for StringSink<'a>
impl<'a> Send for StringSink<'a>
impl<'a> Sync for StringSink<'a>
impl<'a> Unpin for StringSink<'a>
impl<'a> UnsafeUnpin for StringSink<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more