Struct Writer

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

A buffered writer for serializing AST/AIM data structures.

The Writer provides efficient serialization of AST/AIM components to their text representation. It uses buffered writing with specialized formatting functions for different data types, providing optimal performance for generating AIM files.

§Implementation Details

The Writer uses several optimization techniques:

  • Buffered writing with a single String buffer to minimize allocations
  • Efficient number formatting using itoa and ryu crates
  • Direct character writing when possible
  • Specialized formatters for each data type

Implementations§

Source§

impl Writer

Source

pub fn new(format: PrintMode, prefix: Prefix) -> Self

Creates a new Writer instance with an empty buffer.

§Arguments
  • format - The PrintMode to use for output formatting
§Returns
  • Writer - A new Writer instance
Source

pub fn stringizer() -> Self

Creates a new Writer instance for writing with an empty buffer.

§Returns
  • Writer - A new Writer instance
Source

pub fn is_stringizer(&self) -> bool

Source

pub fn sanitizer() -> Self

Creates a new Writer instance for sanitized writing with an empty buffer.

§Returns
  • Writer - A new sanitized Writer instance
Source

pub fn is_sanitizer(&self) -> bool

Source

pub fn formulizer() -> Self

Creates a new Writer instance for writing formulas with an empty buffer.

§Returns
  • Writer - A new formula Writer instance
Source

pub fn is_formulizer(&self) -> bool

Source

pub fn to_sanitized(text: &str) -> String

Source

pub fn to_formula(text: &str) -> String

Source

pub fn prefix(&self) -> Prefix

Source

pub fn print_mode(&self) -> PrintMode

Source

pub fn write_str(&mut self, s: &str)

Writes a string slice to the buffer.

§Arguments
  • s - The string slice to write
Source

pub fn write_char(&mut self, c: char)

Writes a single character to the buffer.

§Arguments
  • c - The character to write
Source

pub fn write_eol(&mut self)

Writes a line ending (newline character) to the buffer.

Source

pub fn write_line(&mut self, s: &str)

Writes a string slice and line ending to the buffer.

§Arguments
  • s - The string slice to write
Source

pub fn write_f64(&mut self, value: f64)

Writes a floating-point number to the buffer using efficient formatting.

This method uses the ryu crate for efficient float-to-string conversion and removes unnecessary trailing “.0” for integer values.

§Arguments
  • value - The f64 value to write
Source

pub fn write_unsigned(&mut self, value: u32)

Writes an unsigned integer to the buffer using efficient formatting.

This method uses the itoa crate for efficient integer-to-string conversion.

§Arguments
  • value - The u32 value to write
Source

pub fn print(&mut self, text: &str)

Print text with the current mode’s formatting rules.

§Arguments
  • text - The text to print
Source

pub fn escape(&mut self, text: &str)

Writes a string literal with proper escaping.

This method properly escapes special characters in string literals:

  • " becomes \"
  • \ becomes \\
  • Control characters like newline, tab, etc. are escaped appropriately
§Arguments
  • text - The text to escape and write
Source

pub fn quote_escape(&mut self, text: &str)

Writes a string literal with proper quoting and escaping.

This method surrounds the text with double quotes and applies proper escaping for special characters.

§Arguments
  • text - The text to quote, escape, and write
Source

pub fn tag_escape(&mut self, text: &str)

Writes a string literal surrounded by angle brackets with proper escaping.

This method surrounds the text with angle brackets and applies proper escaping for special characters.

§Arguments
  • text - The text to tag, escape, and write
Source

pub fn write_date(&mut self, date: &DateTime)

Writes a date/time value in ISO 8601 format.

The date is formatted as: YYYY-MM-DDTHH:MM:SS.sss

§Arguments
  • date - The DateTime to format and write
Source

pub fn write_bool(&mut self, state: bool)

Writes a boolean value as “true” or “false”.

§Arguments
  • state - The boolean value to write
Source

pub fn print_task(&mut self, state: &Option<bool>, text: &str)

Print a task with the current mode’s formatting rules.

§Arguments
  • state - The task status (Some(true) = completed, Some(false) = failed, None = pending)
  • text - The task text
Source

pub fn write_version(&mut self, epoc: u32, partial: u32)

Writes a version header in the format [epoch[:partial]]\n.

§Arguments
  • epoc - The epoch number
  • partial - The partial version number
Source

pub fn print_literal(&mut self, literal: &Literal)

Print a literal with the current mode’s formatting rules.

§Arguments
  • literal - The literal to print
Source

pub fn write_reference(&mut self, reference: &Reference)

Writes a reference in its textual representation.

§Arguments
  • reference - The reference to write
Source

pub fn print_format( &mut self, instruction: &str, format: &str, array: &Vec<String>, )

Print format information with the current mode’s formatting rules.

§Arguments
  • instruction - The instruction text
  • format - The format text
  • array - The array of format parameters
Source

pub fn write_prefix(&mut self, indent: isize, prefix: &Prefix, index: usize)

Writes a list prefix based on the prefix type and index.

§Arguments
  • prefix - The prefix type to write
  • index - The index for ordered lists
Source

pub fn print_errata(&mut self, reason: &str, formula: &str, location: &str)

Source

pub fn print_value(&mut self, prefix: &Prefix, value: &Value)

Print format information with the current mode’s formatting rules.

§Arguments
  • prefix - The instruction text
  • format - The format text
  • array - The array of format parameters
Source

pub fn write_unary_op(&mut self, op: &str, unary: &dyn ExpressionLike)

Writes a unary operation with the operator and operand.

§Arguments
  • op - The operator string
  • unary - The operand expression
Source

pub fn write_binary_op( &mut self, left: &dyn ExpressionLike, op: &str, right: &dyn ExpressionLike, )

Writes a binary operation with left operand, operator, and right operand.

§Arguments
  • left - The left operand expression
  • op - The operator string
  • right - The right operand expression
Source

pub fn finish(self) -> String

Consumes the writer and returns the final string buffer.

§Returns
  • String - The final accumulated string

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§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,