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§anchor_counter: usize§indent_style: IndentStyle§yaml_version: Option<(u8, u8)>§tag_directives: Vec<(String, String)>Implementations§
Source§impl BasicEmitter
impl BasicEmitter
Sourcepub fn with_indent(indent: usize) -> Self
pub fn with_indent(indent: usize) -> Self
Create an emitter with custom indent
Sourcepub fn with_indent_style(indent_style: IndentStyle) -> Self
pub fn with_indent_style(indent_style: IndentStyle) -> Self
Create an emitter with specific indent style
Sourcepub fn set_yaml_version(&mut self, major: u8, minor: u8)
pub fn set_yaml_version(&mut self, major: u8, minor: u8)
Set the YAML version directive
Sourcepub fn add_tag_directive(&mut self, handle: String, prefix: String)
pub fn add_tag_directive(&mut self, handle: String, prefix: String)
Add a TAG directive
Sourcepub fn clear_directives(&mut self)
pub fn clear_directives(&mut self)
Clear all directives
Sourcefn emit_directives<W: Write>(&self, writer: &mut W) -> Result<()>
fn emit_directives<W: Write>(&self, writer: &mut W) -> Result<()>
Emit directives to the writer
Analyze the value tree to identify shared values that need anchors
Sourcefn count_value_occurrences(
&self,
value: &Value,
counts: &mut HashMap<Value, usize>,
)
fn count_value_occurrences( &self, value: &Value, counts: &mut HashMap<Value, usize>, )
Recursively count occurrences of each value
Sourceconst fn is_complex_value(&self, value: &Value) -> bool
const fn is_complex_value(&self, value: &Value) -> bool
Check if a value is complex enough to warrant anchor/alias handling
Sourcefn next_anchor_name(&mut self) -> String
fn next_anchor_name(&mut self) -> String
Generate next anchor name
Sourcepub const fn set_indent_style(&mut self, indent_style: IndentStyle)
pub const fn set_indent_style(&mut self, indent_style: IndentStyle)
Update the indent style (useful for round-trip preservation)
Sourcefn emit_leading_comments<W: Write>(
&self,
comments: &[String],
writer: &mut W,
) -> Result<()>
fn emit_leading_comments<W: Write>( &self, comments: &[String], writer: &mut W, ) -> Result<()>
Write leading comments to the output
Sourcefn emit_trailing_comment<W: Write>(
&self,
comment: &str,
writer: &mut W,
) -> Result<()>
fn emit_trailing_comment<W: Write>( &self, comment: &str, writer: &mut W, ) -> Result<()>
Write a trailing comment on the same line
Sourcefn emit_inner_comments<W: Write>(
&self,
comments: &[String],
writer: &mut W,
) -> Result<()>
fn emit_inner_comments<W: Write>( &self, comments: &[String], writer: &mut W, ) -> Result<()>
Write inner comments (between collection items)
Sourcefn emit_scalar<W: Write>(&self, value: &Value, writer: &mut W) -> Result<()>
fn emit_scalar<W: Write>(&self, value: &Value, writer: &mut W) -> Result<()>
Emit a scalar value
Sourcefn emit_scalar_with_comments<W: Write>(
&self,
value: &Value,
comments: Option<&Comments>,
writer: &mut W,
) -> Result<()>
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
Sourcefn emit_scalar_with_comments_and_style<W: Write>(
&self,
value: &Value,
comments: Option<&Comments>,
quote_style: Option<&QuoteStyle>,
writer: &mut W,
) -> Result<()>
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
Sourcefn emit_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>
fn emit_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>
Emit a string, choosing appropriate quoting style
Sourcefn emit_string_with_style<W: Write>(
&self,
s: &str,
preferred_style: Option<&QuoteStyle>,
writer: &mut W,
) -> Result<()>
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
Sourcefn needs_quoting(&self, s: &str) -> bool
fn needs_quoting(&self, s: &str) -> bool
Check if a string needs to be quoted
Sourcefn emit_double_quoted_string<W: Write>(
&self,
s: &str,
writer: &mut W,
) -> Result<()>
fn emit_double_quoted_string<W: Write>( &self, s: &str, writer: &mut W, ) -> Result<()>
Emit a double-quoted string
Sourcefn emit_single_quoted_string<W: Write>(
&self,
s: &str,
writer: &mut W,
) -> Result<()>
fn emit_single_quoted_string<W: Write>( &self, s: &str, writer: &mut W, ) -> Result<()>
Emit a single-quoted string
Sourcefn emit_quoted_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>
fn emit_quoted_string<W: Write>(&self, s: &str, writer: &mut W) -> Result<()>
Emit a quoted string (legacy method)
Sourcefn emit_sequence<W: Write>(
&mut self,
seq: &[Value],
writer: &mut W,
) -> Result<()>
fn emit_sequence<W: Write>( &mut self, seq: &[Value], writer: &mut W, ) -> Result<()>
Emit a sequence (array/list)
Sourcefn emit_mapping_with_anchor<W: Write>(
&mut self,
map: &IndexMap<Value, Value>,
anchor: &str,
writer: &mut W,
) -> Result<()>
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
Sourcefn emit_mapping<W: Write>(
&mut self,
map: &IndexMap<Value, Value>,
writer: &mut W,
) -> Result<()>
fn emit_mapping<W: Write>( &mut self, map: &IndexMap<Value, Value>, writer: &mut W, ) -> Result<()>
Emit a mapping (dictionary/object)
Sourcefn emit_mapping_flow_style<W: Write>(
&self,
map: &IndexMap<Value, Value>,
writer: &mut W,
) -> Result<()>
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
Sourcefn emit_sequence_flow_style<W: Write>(
&self,
seq: &[Value],
writer: &mut W,
) -> Result<()>
fn emit_sequence_flow_style<W: Write>( &self, seq: &[Value], writer: &mut W, ) -> Result<()>
Emit a sequence in flow style for complex keys
Sourcefn emit_value<W: Write>(&mut self, value: &Value, writer: &mut W) -> Result<()>
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
Sourcefn emit_value_simple<W: Write>(
&mut self,
value: &Value,
writer: &mut W,
) -> Result<()>
fn emit_value_simple<W: Write>( &mut self, value: &Value, writer: &mut W, ) -> Result<()>
Emit any value (old method for backwards compatibility)
Sourcefn emit_commented_value<W: Write>(
&mut self,
commented: &CommentedValue,
writer: &mut W,
) -> Result<()>
fn emit_commented_value<W: Write>( &mut self, commented: &CommentedValue, writer: &mut W, ) -> Result<()>
Emit a commented value with full comment and style support
Sourcepub fn emit_commented_value_public<W: Write>(
&mut self,
commented: &CommentedValue,
writer: W,
) -> Result<()>
pub fn emit_commented_value_public<W: Write>( &mut self, commented: &CommentedValue, writer: W, ) -> Result<()>
Emit a CommentedValue with comment preservation (public API)