pub(crate) fn join(path: &str, ident: &str) -> String {
if path.is_empty() {
ident.to_string()
} else {
format!("{path}::{ident}")
}
}
pub(crate) fn declarator_name(declarator: &crate::hir::Declarator) -> String {
match declarator {
crate::hir::Declarator::SimpleDeclarator(simple) => simple.0.clone(),
crate::hir::Declarator::ArrayDeclarator(array) => array.ident.clone(),
}
}
pub(crate) fn attribute_name(attribute: &crate::hir::AttrDcl) -> String {
use crate::hir::{AttrDclInner, AttrDeclarator};
match &attribute.decl {
AttrDclInner::ReadonlyAttrSpec(spec) => spec
.declarator
.declarators()
.iter()
.map(|decl| decl.0.as_str())
.collect::<Vec<_>>()
.join(","),
AttrDclInner::AttrSpec(spec) => match &spec.declarator {
AttrDeclarator::SimpleDeclarator(declarators) => declarators
.iter()
.map(|simple| simple.0.clone())
.collect::<Vec<_>>()
.join(", "),
AttrDeclarator::WithRaises { declarator, .. } => declarator.0.clone(),
},
}
}
pub(crate) fn declarators_name(declarators: &[crate::hir::Declarator]) -> String {
declarators
.iter()
.map(declarator_name)
.collect::<Vec<_>>()
.join(", ")
}