use std::sync::Arc;
use crate::ir::cfg::{cfg_list, predicate_text};
pub(in crate::ir::extract) struct CfgGate {
pub(in crate::ir::extract) predicate: Arc<str>,
pub(in crate::ir::extract) feature: Option<Arc<str>>,
}
pub(in crate::ir::extract) fn cfg_gate(attr: &syn::Attribute) -> Option<CfgGate> {
let list = cfg_list(attr)?;
Some(CfgGate {
predicate: predicate_text(list),
feature: feature_name(list),
})
}
fn feature_name(list: &syn::MetaList) -> Option<Arc<str>> {
let name_value = list.parse_args::<syn::MetaNameValue>().ok()?;
match (name_value.path.is_ident("feature"), &name_value.value) {
(
true,
syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(feature),
..
}),
) => Some(Arc::from(feature.value())),
_ => None,
}
}