Make id_raw return Option<&ImmutableString>
This commit is contained in:
parent
e3b7aa47a0
commit
70a0d6ce58
@ -129,7 +129,7 @@ impl Imports {
|
||||
pub fn get_fn(
|
||||
&self,
|
||||
hash: NonZeroU64,
|
||||
) -> Option<(&CallableFunction, &Option<ImmutableString>)> {
|
||||
) -> Option<(&CallableFunction, Option<&ImmutableString>)> {
|
||||
self.0
|
||||
.iter()
|
||||
.rev()
|
||||
@ -2051,11 +2051,11 @@ impl Engine {
|
||||
.get_fn(hash_fn, false)
|
||||
.map(|f| (f, None))
|
||||
.or_else(|| {
|
||||
self.global_modules.iter().find_map(|m| {
|
||||
m.get_fn(hash_fn, false).map(|f| (f, m.id_raw().as_ref()))
|
||||
self.global_modules
|
||||
.iter()
|
||||
.find_map(|m| m.get_fn(hash_fn, false).map(|f| (f, m.id_raw())))
|
||||
})
|
||||
})
|
||||
.or_else(|| mods.get_fn(hash_fn).map(|(f, source)| (f, source.as_ref())))
|
||||
.or_else(|| mods.get_fn(hash_fn))
|
||||
{
|
||||
// op= function registered as method
|
||||
Some((func, source)) if func.is_method() => {
|
||||
|
@ -190,13 +190,12 @@ impl Engine {
|
||||
.or_else(|| {
|
||||
self.global_modules.iter().find_map(|m| {
|
||||
m.get_fn(hash_fn, false)
|
||||
.cloned()
|
||||
.map(|f| (f, m.id_raw().clone()))
|
||||
.map(|f| (f.clone(), m.id_raw().cloned()))
|
||||
})
|
||||
})
|
||||
.or_else(|| {
|
||||
mods.get_fn(hash_fn)
|
||||
.map(|(f, source)| (f.clone(), source.clone()))
|
||||
.map(|(f, source)| (f.clone(), source.cloned()))
|
||||
})
|
||||
});
|
||||
|
||||
@ -584,13 +583,13 @@ impl Engine {
|
||||
.iter()
|
||||
.find_map(|&m| {
|
||||
m.get_fn(hash_script, pub_only)
|
||||
.map(|f| (f, m.id_raw().clone()))
|
||||
.map(|f| (f, m.id_raw().cloned()))
|
||||
})
|
||||
//.or_else(|| self.global_namespace.get_fn(hash_script, pub_only))
|
||||
.or_else(|| {
|
||||
self.global_modules.iter().find_map(|m| {
|
||||
m.get_fn(hash_script, false)
|
||||
.map(|f| (f, m.id_raw().clone()))
|
||||
.map(|f| (f, m.id_raw().cloned()))
|
||||
})
|
||||
})
|
||||
//.or_else(|| mods.iter().find_map(|(_, m)| m.get_qualified_fn(hash_script).map(|f| (f, m.id_raw().clone()))))
|
||||
@ -1224,7 +1223,7 @@ impl Engine {
|
||||
let new_scope = &mut Default::default();
|
||||
let fn_def = f.get_fn_def().clone();
|
||||
|
||||
let mut source = module.id_raw().clone();
|
||||
let mut source = module.id_raw().cloned();
|
||||
mem::swap(&mut state.source, &mut source);
|
||||
|
||||
let level = level + 1;
|
||||
@ -1237,10 +1236,10 @@ impl Engine {
|
||||
|
||||
result
|
||||
}
|
||||
Some(f) if f.is_plugin_fn() => f.get_plugin_fn().clone().call(
|
||||
(self, module.id_raw().as_ref(), &*mods, lib).into(),
|
||||
args.as_mut(),
|
||||
),
|
||||
Some(f) if f.is_plugin_fn() => f
|
||||
.get_plugin_fn()
|
||||
.clone()
|
||||
.call((self, module.id_raw(), &*mods, lib).into(), args.as_mut()),
|
||||
Some(f) if f.is_native() => {
|
||||
if !f.is_method() {
|
||||
// Clone first argument
|
||||
@ -1251,10 +1250,7 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
f.get_native_fn()(
|
||||
(self, module.id_raw().as_ref(), &*mods, lib).into(),
|
||||
args.as_mut(),
|
||||
)
|
||||
f.get_native_fn()((self, module.id_raw(), &*mods, lib).into(), args.as_mut())
|
||||
}
|
||||
Some(f) => unreachable!("unknown function type: {:?}", f),
|
||||
None if def_val.is_some() => Ok(def_val.unwrap().clone()),
|
||||
|
@ -252,8 +252,8 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Get the ID of the [`Module`] as an [`ImmutableString`], if any.
|
||||
pub fn id_raw(&self) -> &Option<ImmutableString> {
|
||||
&self.id
|
||||
pub fn id_raw(&self) -> Option<&ImmutableString> {
|
||||
self.id.as_ref()
|
||||
}
|
||||
|
||||
/// Set the ID of the [`Module`].
|
||||
|
Loading…
Reference in New Issue
Block a user