#![allow(dead_code)]
use derive_more::Constructor;
use enumflags2::{bitflags, BitFlags};
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use smol_str::SmolStr;
#[derive(Constructor, Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct RustSourceItemPath {
pub module: SmolStr,
pub name: SmolStr,
}
impl RustSourceItemPath {
pub fn get_fully_qualified_name(&self) -> SmolStr {
if self.module.is_empty() {
SmolStr::new(self.name.as_str())
} else {
SmolStr::new(format!("{}::{}", self.module, self.name).as_str())
}
}
pub fn short_token_stream(&self, target_module: &str) -> TokenStream {
if self.module == target_module {
let ident = syn::Ident::new(&self.name, Span::call_site());
quote::quote!(#ident)
} else {
self.to_token_stream()
}
}
}
impl ToTokens for RustSourceItemPath {
fn to_tokens(&self, tokens: &mut TokenStream) {
let fq_name = self.get_fully_qualified_name();
let current = syn::parse_str::<TokenStream>(&fq_name).unwrap();
tokens.extend(current)
}
}
#[bitflags]
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub(crate) enum RustSourceItemCategory {
ConstVarDecls,
TraitImpls,
TypeImpls,
TypeDefs,
}
#[derive(Constructor, Debug)]
pub(crate) struct RustSourceItem {
pub catagories: BitFlags<RustSourceItemCategory>,
pub path: RustSourceItemPath,
pub tokenstream: TokenStream,
}