helm-rs 0.1.1

Typed Rust API for Helm 4: swappable backends, native chart, values and release reading
Documentation
//! The node tree, mirroring `yaml.Node`.

/// What a node is (`yaml.Kind`).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::schema::generate) enum Kind {
    Document,
    Sequence,
    Mapping,
    Scalar,
    Alias,
}

/// How a node was written (`yaml.Style`).
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub(in crate::schema::generate) struct Style {
    pub(in crate::schema::generate) tagged: bool,
    pub(in crate::schema::generate) double: bool,
    pub(in crate::schema::generate) single: bool,
    pub(in crate::schema::generate) literal: bool,
    pub(in crate::schema::generate) folded: bool,
    pub(in crate::schema::generate) flow: bool,
}

impl Style {
    /// Whether the scalar was written quoted or as a block scalar.
    pub(in crate::schema::generate) fn indicates_string(self) -> bool {
        self.double || self.single || self.literal || self.folded
    }
}

/// A node of the YAML tree. Children and alias targets are indexes into [`Doc::nodes`].
#[derive(Debug, Clone)]
pub(in crate::schema::generate) struct Node {
    pub(in crate::schema::generate) kind: Kind,
    pub(in crate::schema::generate) style: Style,
    /// The short tag (`!!str`), after implicit resolution.
    pub(in crate::schema::generate) tag: String,
    pub(in crate::schema::generate) value: String,
    pub(in crate::schema::generate) anchor: String,
    /// For an alias, the node it refers to.
    pub(in crate::schema::generate) alias: Option<usize>,
    pub(in crate::schema::generate) content: Vec<usize>,
    pub(in crate::schema::generate) head_comment: String,
    pub(in crate::schema::generate) line_comment: String,
    pub(in crate::schema::generate) foot_comment: String,
    /// 1-based line.
    pub(in crate::schema::generate) line: usize,
    /// 1-based column.
    pub(in crate::schema::generate) column: usize,
}

impl Node {
    pub(in crate::schema::generate) fn new(kind: Kind) -> Self {
        Self {
            kind,
            style: Style::default(),
            tag: String::new(),
            value: String::new(),
            anchor: String::new(),
            alias: None,
            content: Vec::new(),
            head_comment: String::new(),
            line_comment: String::new(),
            foot_comment: String::new(),
            line: 0,
            column: 0,
        }
    }
}

/// A parsed document: an arena of nodes and the document node, if the input had a document.
#[derive(Debug, Clone, Default)]
pub(in crate::schema::generate) struct Doc {
    pub(in crate::schema::generate) nodes: Vec<Node>,
    pub(in crate::schema::generate) root: Option<usize>,
}

impl Doc {
    /// Adds a node to the arena.
    pub(in crate::schema::generate) fn add(&mut self, node: Node) -> usize {
        self.nodes.push(node);

        self.nodes.len() - 1
    }
}