toml_input/
comment.rs

1use crate::{config::TomlConfig, error::Error, util, PrimValue};
2
3#[derive(Debug, Clone, PartialEq)]
4#[derive(Default)]
5pub enum CommentType {
6    #[default]
7    None,
8    Root,
9    Section,
10    BlockField,
11    BlockVariant,
12}
13
14
15#[derive(Debug, Clone, Default)]
16pub struct Comment {
17    pub defined_docs: String,
18    pub valued_docs: String,
19    pub wrap_type: String,
20    pub inner_type: String,
21    pub inner_default: PrimValue,
22    pub comment_type: CommentType,
23    pub config: TomlConfig,
24}
25
26impl Comment {
27    pub fn is_empty(&self) -> bool {
28        self.defined_docs.trim().is_empty() && self.valued_docs.trim().is_empty()
29    }
30
31    pub fn render(&self) -> Result<String, Error> {
32        let text = if !self.valued_docs.is_empty() {
33            self.valued_docs.clone()
34        } else {
35            self.defined_docs.clone()
36        };
37        Ok(util::comment_lines(&text))
38    }
39}