code_gen/rust/common/
with_comments.rs1use crate::rust::CommentType;
2use crate::CodeBuffer;
3
4pub trait WithComments: Sized {
6 fn comments(&self) -> &[String];
8
9 fn with_comment<S>(mut self, comment: S) -> Self
11 where
12 S: Into<String>,
13 {
14 self.add_comment(comment);
15 self
16 }
17
18 fn add_comment<S>(&mut self, comment: S)
20 where
21 S: Into<String>;
22
23 fn write_comments(&self, comment_type: CommentType, b: &mut CodeBuffer, level: usize) {
25 for line in self.comments() {
26 comment_type.write_line(b, level, line.as_str());
27 }
28 }
29}