code_gen/rust/common/
with_attributes.rs1use crate::CodeBuffer;
2
3pub trait WithAttributes: Sized {
5 fn attributes(&self) -> &[String];
7
8 fn add_attribute<S>(&mut self, attribute: S)
10 where
11 S: Into<String>;
12
13 fn with_attribute<S>(mut self, attribute: S) -> Self
15 where
16 S: Into<String>,
17 {
18 self.add_attribute(attribute);
19 self
20 }
21
22 fn write_attributes(&self, b: &mut CodeBuffer, level: usize) {
24 for attribute in self.attributes() {
25 b.indent(level);
26 b.write("#[");
27 b.write(attribute);
28 b.write("]");
29 b.end_line();
30 }
31 }
32}