babbel_yaml 0.1.1

Fast, modular YAML 1.2 parser and emitter with anchors, aliases, and tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Serialization Abstractions (OCP & DIP)
//!
//! Provides core traits for serializing YAML Node trees into different text formats.

use crate::error::Result;
use crate::io::traits::IDestination;
use crate::nodes::node::Node;

/// Trait defining the contract for serializing a Node AST into a target format.
pub trait NodeSerializer {
    /// Serialize a Node tree to the destination.
    fn serialize(&self, node: &Node, dest: &mut dyn IDestination) -> Result<()>;

    /// Serialize a Node tree to the destination with pretty formatting.
    fn serialize_pretty(&self, node: &Node, dest: &mut dyn IDestination) -> Result<()> {
        self.serialize(node, dest)
    }
}