Skip to main content

JsonBuffer

Struct JsonBuffer 

Source
pub struct JsonBuffer<const N: usize> { /* private fields */ }
Expand description

Stack-allocated, grow-only JSON buffer.

This structure exposes only const fn methods so it can be used from compile-time generated serializers.

Implementations§

Source§

impl<const N: usize> JsonBuffer<N>

Source

pub const fn new() -> Self

Create an empty buffer.

Source

pub const fn len(&self) -> usize

Current number of bytes written.

Source

pub const fn capacity(&self) -> usize

Maximum capacity in bytes.

Source

pub const fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub const fn push_byte(&mut self, byte: u8)

Push a single byte, asserting capacity.

Source

pub const fn push_lit(&mut self, text: &str)

Append a raw UTF-8 literal.

Source

pub const fn push_escaped(&mut self, value: &str)

Append a string value with JSON escaping.

Source

pub const fn as_bytes(&self) -> &[u8]

View the written bytes as a slice.

Source

pub const fn as_str(&self) -> &str

Interpret the contents as a UTF-8 string.

Source

pub const fn into_inner(self) -> ([u8; N], usize)

Move the buffer out, returning the backing array and length.

Source

pub const fn clear(&mut self)

Reset the buffer to empty without altering allocation.

Trait Implementations§

Source§

impl<const N: usize> Default for JsonBuffer<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize> Index<usize> for JsonBuffer<N>

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for JsonBuffer<N>
where [u8; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for JsonBuffer<N>
where [u8; N]: RefUnwindSafe,

§

impl<const N: usize> Send for JsonBuffer<N>
where [u8; N]: Send,

§

impl<const N: usize> Sync for JsonBuffer<N>
where [u8; N]: Sync,

§

impl<const N: usize> Unpin for JsonBuffer<N>
where [u8; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for JsonBuffer<N>
where [u8; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for JsonBuffer<N>
where [u8; N]: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.