Reduce usage of as_ref and as_mut.

This commit is contained in:
Stephen Chung
2022-07-05 16:26:38 +08:00
parent 9319f87a7b
commit b6528bd51d
33 changed files with 211 additions and 137 deletions

View File

@@ -197,7 +197,7 @@ impl GlobalRuntimeState<'_> {
.iter()
.rev()
.zip(self.modules.iter().rev())
.map(|(name, module)| (name.as_str(), module.as_ref()))
.map(|(name, module)| (name.as_str(), &**module))
}
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in reverse order.
///
@@ -327,6 +327,21 @@ impl IntoIterator for GlobalRuntimeState<'_> {
}
}
#[cfg(not(feature = "no_module"))]
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
type Item = (&'a Identifier, &'a crate::Shared<crate::Module>);
type IntoIter = std::iter::Zip<
std::iter::Rev<std::slice::Iter<'a, Identifier>>,
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
let x = self.keys.iter().rev().zip(self.modules.iter().rev());
x
}
}
#[cfg(not(feature = "no_module"))]
impl<K: Into<Identifier>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
for GlobalRuntimeState<'_>