use crate::CodeBuffer;
pub trait WithAttributes: Sized {
fn attributes(&self) -> &[String];
fn add_attribute<S>(&mut self, attribute: S)
where
S: Into<String>;
#[must_use]
fn with_attribute<S>(mut self, attribute: S) -> Self
where
S: Into<String>,
{
self.add_attribute(attribute);
self
}
fn write_attributes(&self, b: &mut CodeBuffer, level: usize) {
for attribute in self.attributes() {
b.indent(level);
b.write("#[");
b.write(attribute);
b.push(']');
b.end_line();
}
}
}