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
itoaandryucrates - Direct character writing when possible
- Specialized formatters for each data type
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn stringizer() -> Self
pub fn stringizer() -> Self
Creates a new Writer instance for writing with an empty buffer.
§Returns
Writer- A new Writer instance
pub fn is_stringizer(&self) -> bool
Sourcepub fn sanitizer() -> Self
pub fn sanitizer() -> Self
Creates a new Writer instance for sanitized writing with an empty buffer.
§Returns
Writer- A new sanitized Writer instance
pub fn is_sanitizer(&self) -> bool
Sourcepub fn formulizer() -> Self
pub fn formulizer() -> Self
Creates a new Writer instance for writing formulas with an empty buffer.
§Returns
Writer- A new formula Writer instance
pub fn is_formulizer(&self) -> bool
pub fn to_sanitized(text: &str) -> String
pub fn to_formula(text: &str) -> String
pub fn prefix(&self) -> Prefix
pub fn print_mode(&self) -> PrintMode
Sourcepub fn write_char(&mut self, c: char)
pub fn write_char(&mut self, c: char)
Sourcepub fn write_line(&mut self, s: &str)
pub fn write_line(&mut self, s: &str)
Sourcepub fn write_f64(&mut self, value: f64)
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
Sourcepub fn write_unsigned(&mut self, value: u32)
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
Sourcepub fn escape(&mut self, text: &str)
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
Sourcepub fn quote_escape(&mut self, text: &str)
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
Sourcepub fn tag_escape(&mut self, text: &str)
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
Sourcepub fn write_date(&mut self, date: &DateTime)
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
Sourcepub fn write_bool(&mut self, state: bool)
pub fn write_bool(&mut self, state: bool)
Sourcepub fn print_task(&mut self, state: &Option<bool>, text: &str)
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
Sourcepub fn write_version(&mut self, epoc: u32, partial: u32)
pub fn write_version(&mut self, epoc: u32, partial: u32)
Writes a version header in the format [epoch[:partial]]\n.
§Arguments
epoc- The epoch numberpartial- The partial version number
Sourcepub fn print_literal(&mut self, literal: &Literal)
pub fn print_literal(&mut self, literal: &Literal)
Sourcepub fn write_reference(&mut self, reference: &Reference)
pub fn write_reference(&mut self, reference: &Reference)
Sourcepub fn print_format(
&mut self,
instruction: &str,
format: &str,
array: &Vec<String>,
)
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 textformat- The format textarray- The array of format parameters
Sourcepub fn write_prefix(&mut self, indent: isize, prefix: &Prefix, index: usize)
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 writeindex- The index for ordered lists
pub fn print_errata(&mut self, reason: &str, formula: &str, location: &str)
Sourcepub fn print_value(&mut self, prefix: &Prefix, value: &Value)
pub fn print_value(&mut self, prefix: &Prefix, value: &Value)
Print format information with the current mode’s formatting rules.
§Arguments
prefix- The instruction textformat- The format textarray- The array of format parameters
Sourcepub fn write_unary_op(&mut self, op: &str, unary: &dyn ExpressionLike)
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 stringunary- The operand expression
Sourcepub fn write_binary_op(
&mut self,
left: &dyn ExpressionLike,
op: &str,
right: &dyn ExpressionLike,
)
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 expressionop- The operator stringright- The right operand expression