use std::collections::HashMap;
use proc_macro2::{TokenStream, TokenTree};
#[derive(Clone, Copy)]
pub(crate) enum ConstCtx<'a> {
Attribute {
trait_def: &'a syn::ItemTrait,
trait_full_path: &'a TokenStream,
},
Trait {
user_table: &'a UserConsts,
},
}
pub(crate) type UserConsts = HashMap<String, Vec<TokenTree>>;
impl<'a> ConstCtx<'a> {
pub(crate) fn user_table(&self) -> Option<&'a UserConsts> {
match self {
&ConstCtx::Trait { user_table } => user_table.into(),
ConstCtx::Attribute { .. } => None,
}
}
pub(crate) fn trait_def(&self) -> Option<&'a syn::ItemTrait> {
match self {
&ConstCtx::Attribute { trait_def, .. } => trait_def.into(),
ConstCtx::Trait { .. } => None,
}
}
pub(crate) fn trait_full_path(&self) -> Option<&'a TokenStream> {
match self {
&ConstCtx::Attribute { trait_full_path, .. } => trait_full_path.into(),
ConstCtx::Trait { .. } => None,
}
}
}