Pass crate environment to proc macros

This commit is contained in:
Jonas Schievink
2020-12-11 14:57:50 +01:00
parent 798968e1e3
commit 70877428a8
6 changed files with 42 additions and 9 deletions

View File

@@ -151,8 +151,12 @@ pub enum ProcMacroKind {
}
pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
-> Result<Subtree, ExpansionError>;
fn expand(
&self,
subtree: &Subtree,
attrs: Option<&Subtree>,
env: &Env,
) -> Result<Subtree, ExpansionError>;
}
#[derive(Debug, Clone)]
@@ -418,6 +422,10 @@ impl Env {
pub fn get(&self, env: &str) -> Option<String> {
self.entries.get(env).cloned()
}
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
self.entries.iter().map(|(k, v)| (k.as_str(), v.as_str()))
}
}
#[derive(Debug)]