Add contains to Scope.
This commit is contained in:
parent
6a6c5f30de
commit
702b2010f2
10
src/scope.rs
10
src/scope.rs
@ -139,6 +139,16 @@ impl<'a> Scope<'a> {
|
|||||||
self.0.truncate(size);
|
self.0.truncate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Does the scope contain the variable?
|
||||||
|
pub fn contains(&self, key: &str) -> bool {
|
||||||
|
self.0
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.rev() // Always search a Scope in reverse order
|
||||||
|
.find(|(_, ScopeEntry { name, .. })| name == key)
|
||||||
|
.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Find a variable in the Scope, starting from the last.
|
/// Find a variable in the Scope, starting from the last.
|
||||||
pub fn get(&self, key: &str) -> Option<(usize, &str, VariableType, Dynamic)> {
|
pub fn get(&self, key: &str) -> Option<(usize, &str, VariableType, Dynamic)> {
|
||||||
self.0
|
self.0
|
||||||
|
Loading…
Reference in New Issue
Block a user