Simplify Pair to fully qualified

This commit is contained in:
David Tolnay 2020-12-21 14:40:50 -08:00
parent 2d99b00fcc
commit dee9fa3853
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -32,19 +32,17 @@ impl Pair {
}
pub fn to_fully_qualified(&self) -> String {
format!("::{}", self.join("::"))
let mut fully_qualified = String::new();
for segment in self.iter_all_segments() {
fully_qualified += "::";
fully_qualified += &segment.to_string();
}
fully_qualified
}
fn iter_all_segments(&self) -> impl Iterator<Item = &Ident> {
self.namespace.iter().chain(iter::once(&self.cxx))
}
fn join(&self, sep: &str) -> String {
self.iter_all_segments()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(sep)
}
}
impl RustName {