cxx/syntax/names.rs

39 lines
973 B
Rust
Raw Normal View History

2021-01-01 14:15:18 -08:00
use crate::syntax::{Lifetimes, NamedType, Pair, Symbol};
use proc_macro2::{Ident, Span};
2020-11-02 00:18:19 -08:00
use std::iter;
2020-12-30 19:48:42 -08:00
use syn::punctuated::Punctuated;
impl Pair {
2020-11-02 00:18:19 -08:00
pub fn to_symbol(&self) -> Symbol {
Symbol::from_idents(self.iter_all_segments())
}
pub fn to_fully_qualified(&self) -> String {
2020-12-21 14:40:50 -08:00
let mut fully_qualified = String::new();
for segment in self.iter_all_segments() {
fully_qualified += "::";
fully_qualified += &segment.to_string();
}
fully_qualified
2020-11-02 00:18:19 -08:00
}
fn iter_all_segments(&self) -> impl Iterator<Item = &Ident> {
self.namespace.iter().chain(iter::once(&self.cxx))
}
}
2021-01-01 14:15:18 -08:00
impl NamedType {
pub fn new(rust: Ident) -> Self {
2020-12-30 19:48:42 -08:00
let generics = Lifetimes {
lt_token: None,
lifetimes: Punctuated::new(),
gt_token: None,
};
2021-01-01 14:15:18 -08:00
NamedType { rust, generics }
}
pub fn span(&self) -> Span {
self.rust.span()
}
}