Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

Writer that builds TOON output string from JSON values.

Implementations§

Source§

impl Writer

Source

pub fn new(options: EncodeOptions) -> Self

Create a new writer with the given options.

Source

pub fn finish(self) -> String

Finish writing and return the complete TOON string.

Source

pub fn write_str(&mut self, s: &str) -> ToonResult<()>

Source

pub fn write_char(&mut self, ch: char) -> ToonResult<()>

Source

pub fn write_newline(&mut self) -> ToonResult<()>

Source

pub fn write_indent(&mut self, depth: usize) -> ToonResult<()>

Source

pub fn write_delimiter(&mut self) -> ToonResult<()>

Source

pub fn write_key(&mut self, key: &str) -> ToonResult<()>

Source

pub fn write_array_header( &mut self, key: Option<&str>, length: usize, fields: Option<&[String]>, depth: usize, ) -> ToonResult<()>

Write an array header with key, length, and optional field list.

Source

pub fn write_empty_array_with_key( &mut self, key: Option<&str>, depth: usize, ) -> ToonResult<()>

Write an empty array header.

Source

pub fn needs_quoting(&self, s: &str, context: QuotingContext) -> bool

Source

pub fn write_quoted_string(&mut self, s: &str) -> ToonResult<()>

Source

pub fn write_value( &mut self, s: &str, context: QuotingContext, ) -> ToonResult<()>

Source

pub fn push_active_delimiter(&mut self, delim: Delimiter)

Push a new delimiter onto the stack (for nested arrays with different delimiters).

Source

pub fn pop_active_delimiter(&mut self)

Pop the active delimiter, keeping at least one (the document default).

Auto Trait Implementations§

§

impl Freeze for Writer

§

impl RefUnwindSafe for Writer

§

impl Send for Writer

§

impl Sync for Writer

§

impl Unpin for Writer

§

impl UnwindSafe for Writer

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.