use std::collections::HashSet;
use super::*;
pub fn extract_exclude_set(
namespace: &initial::Namespace,
bindings_toml_key: &str,
) -> Result<HashSet<String>> {
let Some(config_toml) = &namespace.config_toml else {
return Ok(HashSet::default());
};
let config: toml::Table = toml::from_str(config_toml)?;
let exclude = config
.get("bindings")
.and_then(|b| b.as_table())
.and_then(|b| b.get(bindings_toml_key))
.and_then(|p| p.as_table())
.and_then(|p| p.get("exclude"))
.cloned();
Ok(match exclude {
Some(toml) => toml.try_into()?,
None => HashSet::default(),
})
}
pub fn should_exclude_toplevel_item(name: &str, context: &Context) -> Result<bool> {
let Some(exclude_set) = context.exclude_sets.get(&context.namespace_name()?) else {
return Ok(false);
};
Ok(exclude_set.contains(name))
}
pub fn should_exclude_method(method_name: &str, context: &Context) -> Result<bool> {
let Some(exclude_set) = context.exclude_sets.get(&context.namespace_name()?) else {
return Ok(false);
};
let key = format!("{}.{method_name}", context.current_type_name()?);
Ok(exclude_set.contains(&key))
}