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