Skip to main content

JsonStr

Enum JsonStr 

Source
pub enum JsonStr<'de> {
    Borrowed(&'de str),
    BorrowedNoEsc(&'de str),
    Owned(String),
}
Expand description

A parsed JSON string: either a zero-copy borrow or a heap-allocated value.

The BorrowedNoEsc variant is returned by Scanner::read_str when no escape sequences were present in the JSON input. This lets the serializer skip the find_escape scan entirely — the string is provably escape-free.

Variants§

§

Borrowed(&'de str)

Zero-copy borrow from the input. No longer emitted by Scanner::read_str (use JsonStr::BorrowedNoEsc instead); kept for API compatibility. ToJson will run write_escaped_str on this variant.

§

BorrowedNoEsc(&'de str)

Zero-copy borrow whose content is provably escape-free (the scanner hit a closing " before any \\). The serializer can bypass the find_escape scan and write the bytes directly.

§

Owned(String)

Implementations§

Source§

impl<'de> JsonStr<'de>

Source

pub fn as_borrowed(&self) -> Option<&'de str>

Source

pub fn as_str(&self) -> &str

Source

pub fn into_owned(self) -> String

Trait Implementations§

Source§

impl ToJson for JsonStr<'_>

Source§

fn json_write(&self, w: &mut Vec<u8>)

Source§

fn json_size_hint(&self) -> usize

Hint for the approximate number of bytes this value will serialize to. Read more
Source§

fn to_json_bytes(&self) -> Vec<u8>

Source§

fn to_json_string(&self) -> String

Auto Trait Implementations§

§

impl<'de> Freeze for JsonStr<'de>

§

impl<'de> RefUnwindSafe for JsonStr<'de>

§

impl<'de> Send for JsonStr<'de>

§

impl<'de> Sync for JsonStr<'de>

§

impl<'de> Unpin for JsonStr<'de>

§

impl<'de> UnsafeUnpin for JsonStr<'de>

§

impl<'de> UnwindSafe for JsonStr<'de>

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> ToJsonExt for T
where T: ToJson + ?Sized,

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