aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/macro.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2024-11-10 23:04:33 -0700
committerMelody Horn <melody@boringcactus.com>2024-11-10 23:04:33 -0700
commit825ff799a2154ffb94ef21bbc14e2afe2afa2006 (patch)
treeea65adacd459f4fef69beac960aa3397ed7a66d0 /src/makefile/macro.rs
parent87ce694f4d15d84e5737615b2768deaf866a796d (diff)
downloadmakers-825ff799a2154ffb94ef21bbc14e2afe2afa2006.tar.gz
makers-825ff799a2154ffb94ef21bbc14e2afe2afa2006.zip
overhaul lookup_internal
Diffstat (limited to 'src/makefile/macro.rs')
-rw-r--r--src/makefile/macro.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs
index b135f42..4a82fe9 100644
--- a/src/makefile/macro.rs
+++ b/src/makefile/macro.rs
@@ -11,6 +11,7 @@ use std::rc::Rc;
use super::functions;
use super::token::{Token, TokenString};
use super::ItemSource;
+use super::LookupInternal;
#[cfg(feature = "full")]
use crate::makefile::eval_context::DeferredEvalContext;
use eyre::{bail, Result, WrapErr};
@@ -25,10 +26,6 @@ pub struct Macro {
pub eagerly_expanded: bool,
}
-pub trait LookupInternal: for<'a> Fn(&'a str) -> Result<String> {}
-
-impl<F: for<'a> Fn(&'a str) -> Result<String>> LookupInternal for F {}
-
#[cfg(feature = "full")]
#[derive(Clone, Debug)]
pub enum ExportConfig {
@@ -91,7 +88,7 @@ impl ExportConfig {
pub struct Set<'parent, 'lookup> {
parent: Option<&'parent Set<'parent, 'lookup>>,
pub data: HashMap<String, Macro>,
- lookup_internal: Option<&'lookup dyn LookupInternal>,
+ lookup_internal: Option<LookupInternal<'lookup>>,
#[cfg(feature = "full")]
pub exported: ExportConfig,
warnings: Rc<RefCell<HashSet<String>>>,
@@ -140,8 +137,8 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> {
}
fn lookup_internal(&self, name: &str) -> Result<String> {
- if let Some(lookup) = self.lookup_internal {
- lookup(name)
+ if let Some(lookup) = self.lookup_internal.as_ref() {
+ lookup.lookup(name)
} else if let Some(parent) = self.parent {
parent.lookup_internal(name)
} else {
@@ -341,7 +338,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> {
}
}
- pub fn with_lookup<'l, 's: 'l>(&'s self, lookup: &'l dyn LookupInternal) -> Set<'s, 'l> {
+ pub fn with_lookup<'l, 's: 'l>(&'s self, lookup: LookupInternal<'l>) -> Set<'s, 'l> {
Set {
parent: Some(self),
data: HashMap::new(),
@@ -392,7 +389,10 @@ impl fmt::Debug for Set<'_, '_> {
let mut r#struct = f.debug_struct("Set");
r#struct.field("parent", &self.parent);
r#struct.field("data", &self.data);
- r#struct.field("lookup_internal", &self.lookup_internal.map(|_| ()));
+ r#struct.field(
+ "lookup_internal",
+ &self.lookup_internal.as_ref().map(|_| ()),
+ );
#[cfg(feature = "full")]
r#struct.field("exported", &self.exported);
r#struct.field("warnings", &self.warnings);