use std::fmt::{Display, Formatter, Result};
#[derive(Debug, Clone)]
pub struct Comment {
pub comment: String,
pub docstring: bool,
}
impl Comment {
pub fn new<T: Display>(comment: T) -> Comment {
Comment {
comment: comment.to_string(),
docstring: false,
}
}
pub fn docstring<T: Display>(comment: T) -> Comment {
Comment {
comment: comment.to_string(),
docstring: true,
}
}
}
impl Display for Comment {
fn fmt(&self, f: &mut Formatter) -> Result {
let comment_len = if self.docstring {
""
} else {
"// "
};
write!(f, "{}{}", comment_len, self.comment)
}
}