Use as_deref().

This commit is contained in:
Stephen Chung
2022-11-25 23:03:20 +08:00
parent d645d8271c
commit e8e1706d98
14 changed files with 36546 additions and 74 deletions

View File

@@ -195,10 +195,11 @@ impl GlobalRuntimeState {
#[inline]
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &crate::Module)> {
self.imports
.iter()
.flat_map(|x| x.iter())
.as_deref()
.into_iter()
.flatten()
.rev()
.zip(self.modules.iter().flat_map(|x| x.iter()).rev())
.zip(self.modules.as_deref().into_iter().flatten().rev())
.map(|(name, module)| (name.as_str(), &**module))
}
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in reverse order.
@@ -210,10 +211,11 @@ impl GlobalRuntimeState {
&self,
) -> impl Iterator<Item = (&ImmutableString, &crate::SharedModule)> {
self.imports
.iter()
.flat_map(|x| x.iter())
.as_deref()
.into_iter()
.flatten()
.rev()
.zip(self.modules.iter().flat_map(|x| x.iter()).rev())
.zip(self.modules.as_deref().into_iter().flatten())
}
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order.
///
@@ -224,9 +226,10 @@ impl GlobalRuntimeState {
&self,
) -> impl Iterator<Item = (&ImmutableString, &crate::SharedModule)> {
self.imports
.iter()
.flat_map(|x| x.iter())
.zip(self.modules.iter().flat_map(|x| x.iter()))
.as_deref()
.into_iter()
.flatten()
.zip(self.modules.as_deref().into_iter().flatten())
}
/// Can the particular function with [`Dynamic`] parameter(s) exist in the stack of
/// globally-imported [modules][crate::Module]?

View File

@@ -503,9 +503,10 @@ impl Engine {
#[cfg(not(feature = "no_module"))]
let func = func.or_else(|| global.get_iter(iter_type)).or_else(|| {
self.global_sub_modules
.iter()
.flat_map(|m| m.values())
.find_map(|m| m.get_qualified_iter(iter_type))
.as_deref()
.into_iter()
.flatten()
.find_map(|(_, m)| m.get_qualified_iter(iter_type))
});
let func = func.ok_or_else(|| ERR::ErrorFor(expr.start_position()))?;