wdl_format/element/
node.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! A wrapper for formatting [`AstNode`]s.

use wdl_ast::Element;
use wdl_ast::Node;

use crate::element::FormatElement;
use crate::element::collate;

/// An extension trait for formatting [`Node`]s.
pub trait AstNodeFormatExt {
    /// Consumes `self` and returns the [`Node`] as a [`FormatElement`].
    fn into_format_element(self) -> FormatElement;
}

impl AstNodeFormatExt for Node {
    fn into_format_element(self) -> FormatElement
    where
        Self: Sized,
    {
        let children = collate(&self);
        FormatElement::new(Element::Node(self), children)
    }
}