1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::fmt::{self, Write};
use crate::formatter::Formatter;
/// Used to apply documentation to the module, trait, etc.
#[derive(Debug, Clone)]
pub struct Docs {
/// The documentation to add.
docs: String,
}
impl Docs {
/// Creates new documentation.
///
/// # Arguments
///
/// * `docs` - The docs to add.
pub fn new(docs: &str) -> Self {
Docs {
docs: docs.to_string(),
}
}
/// Formats the documentation using the provided formatter. This will also
/// add the `///` before each line of documentation.
///
/// # Arguments
///
/// * `fmt` - The formatter to use.
pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
for line in self.docs.lines() {
write!(fmt, "/// {}\n", line)?;
}
Ok(())
}
}