| 98 | |
| 99 | impl Config { |
| 100 | fn to_commented_toml(&self) -> Result<String> { |
| 101 | let mut doc = to_document(self)?; |
| 102 | |
| 103 | for (i, (mut key, _value)) in doc.iter_mut().enumerate() { |
| 104 | let decor = key.leaf_decor_mut(); |
| 105 | let docstring = Self::FIELD_DOCS[i]; |
| 106 | |
| 107 | let mut comment = String::new(); |
| 108 | for line in docstring.lines() { |
| 109 | let line = if line.is_empty() { |
| 110 | String::from("#\n") |
| 111 | } else { |
| 112 | format!("# {line}\n") |
| 113 | }; |
| 114 | comment.push_str(&line); |
| 115 | } |
| 116 | decor.set_prefix(comment); |
| 117 | } |
| 118 | Ok(doc.to_string()) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | fn load_config(config: &PathBuf) -> Result<CertBotConfig> { |