Struct BasicEmitter

Source
pub struct BasicEmitter {
    indent: usize,
    current_indent: usize,
    shared_values: HashMap<Value, ValueInfo>,
    anchor_counter: usize,
    indent_style: IndentStyle,
    yaml_version: Option<(u8, u8)>,
    tag_directives: Vec<(String, String)>,
}
Expand description

Basic emitter implementation that generates clean YAML

Fields§

§indent: usize§current_indent: usize§shared_values: HashMap<Value, ValueInfo>§anchor_counter: usize§indent_style: IndentStyle§yaml_version: Option<(u8, u8)>§tag_directives: Vec<(String, String)>

Implementations§

Source§

impl BasicEmitter

Source

pub fn new() -> Self

Create a new emitter with default settings

Source

pub fn with_indent(indent: usize) -> Self

Create an emitter with custom indent

Source

pub fn with_indent_style(indent_style: IndentStyle) -> Self

Create an emitter with specific indent style

Source

pub fn set_yaml_version(&mut self, major: u8, minor: u8)

Set the YAML version directive

Source

pub fn add_tag_directive(&mut self, handle: String, prefix: String)

Add a TAG directive

Source

pub fn clear_directives(&mut self)

Clear all directives

Source

fn emit_directives<W: Write>(&self, writer: &mut W) -> Result<()>

Emit directives to the writer

Source

fn analyze_shared_values(&mut self, value: &Value)

Analyze the value tree to identify shared values that need anchors

Source

fn count_value_occurrences( &self, value: &Value, counts: &mut HashMap<Value, usize>, )

Recursively count occurrences of each value

Source

const fn is_complex_value(&self, value: &Value) -> bool

Check if a value is complex enough to warrant anchor/alias handling

Source

fn next_anchor_name(&mut self) -> String

Generate next anchor name

Source

pub const fn set_indent_style(&mut self, indent_style: IndentStyle)

Update the indent style (useful for round-trip preservation)

Source

fn write_indent<W: Write>(&self, writer: &mut W) -> Result<()>

Write indentation to the output

Source

fn emit_leading_comments<W: Write>( &self, comments: &[String], writer: &mut W, ) -> Result<()>

Write leading comments to the output

Source

fn emit_trailing_comment<W: Write>( &self, comment: &str, writer: &mut W, ) -> Result<()>

Write a trailing comment on the same line

Source

fn emit_inner_comments<W: Write>( &self, comments: &[String], writer: &mut W, ) -> Result<()>

Write inner comments (between collection items)

Source

fn emit_scalar<W: Write>(&self, value: &Value, writer: &mut W) -> Result<()>

Emit a scalar value

Source

fn emit_scalar_with_comments<W: Write>( &self, value: &Value, comments: Option<&Comments>, writer: &mut W, ) -> Result<()>

Emit a scalar value with optional comments and style

Source

fn emit_scalar_with_comments_and_style<W: Write>( &self, value: &Value, comments: Option<&Comments>, quote_style: Option<&QuoteStyle>, writer: &mut W, ) -> Result<()>

Emit a scalar value with optional comments and style information

Source

fn emit_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>

Emit a string, choosing appropriate quoting style

Source

fn emit_string_with_style<W: Write>( &self, s: &str, preferred_style: Option<&QuoteStyle>, writer: &mut W, ) -> Result<()>

Emit a string with specific quote style

Source

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

Check if a string needs to be quoted

Source

fn emit_double_quoted_string<W: Write>( &self, s: &str, writer: &mut W, ) -> Result<()>

Emit a double-quoted string

Source

fn emit_single_quoted_string<W: Write>( &self, s: &str, writer: &mut W, ) -> Result<()>

Emit a single-quoted string

Source

fn emit_quoted_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>

Emit a quoted string (legacy method)

Source

fn emit_sequence<W: Write>( &mut self, seq: &[Value], writer: &mut W, ) -> Result<()>

Emit a sequence (array/list)

Source

fn emit_mapping_with_anchor<W: Write>( &mut self, map: &IndexMap<Value, Value>, anchor: &str, writer: &mut W, ) -> Result<()>

Emit a mapping with an anchor

Source

fn emit_mapping<W: Write>( &mut self, map: &IndexMap<Value, Value>, writer: &mut W, ) -> Result<()>

Emit a mapping (dictionary/object)

Source

fn emit_mapping_flow_style<W: Write>( &self, map: &IndexMap<Value, Value>, writer: &mut W, ) -> Result<()>

Emit a mapping in flow style for complex keys

Source

fn emit_sequence_flow_style<W: Write>( &self, seq: &[Value], writer: &mut W, ) -> Result<()>

Emit a sequence in flow style for complex keys

Source

fn emit_value<W: Write>(&mut self, value: &Value, writer: &mut W) -> Result<()>

Emit any value, dispatching to the appropriate method with anchor/alias support

Source

fn emit_value_simple<W: Write>( &mut self, value: &Value, writer: &mut W, ) -> Result<()>

Emit any value (old method for backwards compatibility)

Source

fn emit_commented_value<W: Write>( &mut self, commented: &CommentedValue, writer: &mut W, ) -> Result<()>

Emit a commented value with full comment and style support

Trait Implementations§

Source§

impl Debug for BasicEmitter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BasicEmitter

Source§

fn default() -> Self

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

impl Emitter for BasicEmitter

Source§

fn emit<W: Write>(&mut self, value: &Value, writer: W) -> Result<()>

Emit a value to the output
Source§

fn emit_commented<W: Write>( &mut self, value: &CommentedValue, writer: W, ) -> Result<()>

Emit a commented value to the output with comment preservation
Source§

fn emit_with_style<W: Write>( &mut self, value: &CommentedValue, indent_style: &IndentStyle, writer: W, ) -> Result<()>

Emit a commented value with specific indent style
Source§

fn reset(&mut self)

Reset the emitter state

Auto Trait Implementations§

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