blob: e7f7c63187366d4356eabd527a1229248f5b3c98 [file] [log] [blame]
use proc_macro2::Ident;
pub enum Block {
AnonymousNamespace,
Namespace(&'static str),
UserDefinedNamespace(Ident),
InlineNamespace(&'static str),
ExternC,
}
impl Block {
pub fn write_begin(&self, out: &mut String) {
if let Block::InlineNamespace(_) = self {
out.push_str("inline ");
}
self.write_common(out);
out.push_str(" {\n");
}
pub fn write_end(&self, out: &mut String) {
out.push_str("} // ");
self.write_common(out);
out.push('\n');
}
fn write_common(&self, out: &mut String) {
match self {
Block::AnonymousNamespace => out.push_str("namespace"),
Block::Namespace(name) => {
out.push_str("namespace ");
out.push_str(name);
}
Block::UserDefinedNamespace(name) => {
out.push_str("namespace ");
out.push_str(&name.to_string());
}
Block::InlineNamespace(name) => {
out.push_str("namespace ");
out.push_str(name);
}
Block::ExternC => out.push_str("extern \"C\""),
}
}
}