2021-01-01 14:15:18 -08:00
|
|
|
use crate::syntax::{Lifetimes, NamedType, Pair, Symbol};
|
2020-11-01 12:34:51 -08:00
|
|
|
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;
|
2020-11-01 12:34:51 -08:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
2020-11-01 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
2021-01-01 14:15:18 -08:00
|
|
|
impl NamedType {
|
2020-12-21 15:03:18 -08:00
|
|
|
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 }
|
2020-11-01 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn span(&self) -> Span {
|
|
|
|
self.rust.span()
|
|
|
|
}
|
|
|
|
}
|