Simplify code, document logic, refactor and better error messages.

This commit is contained in:
Stephen Chung
2020-03-06 01:05:02 +08:00
parent 883f08c026
commit 3d3b939ba6
4 changed files with 220 additions and 150 deletions

View File

@@ -85,6 +85,13 @@ impl Scope {
&mut entry.1
}
/// Get a mutable reference to a variable in the Scope and downcast it to a specific type
pub(crate) fn get_mut_by_type<T: Any + Clone>(&mut self, key: &str, index: usize) -> &mut T {
self.get_mut(key, index)
.downcast_mut::<T>()
.expect("wrong type cast")
}
/// Get an iterator to variables in the Scope.
pub fn iter(&self) -> impl Iterator<Item = (&str, &Dynamic)> {
self.0