From e6bb732f18cd7c631308004f9454791d3c72fff5 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Wed, 1 Feb 2023 19:59:46 -0800 Subject: [PATCH] new implementations and one less lifetime bug Signed-off-by: Ava Hahn --- the_rewrite/src/func.rs | 4 ++++ the_rewrite/src/vars.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/the_rewrite/src/func.rs b/the_rewrite/src/func.rs index 9365168..c0dcdb9 100644 --- a/the_rewrite/src/func.rs +++ b/the_rewrite/src/func.rs @@ -49,6 +49,10 @@ impl<'a> FTable<'a> { pub fn remove(&self, id: String) { self.0.remove(&id); } + + pub fn new() -> FTable<'a> { + FTable{0: HashMap::>::new()} + } } diff --git a/the_rewrite/src/vars.rs b/the_rewrite/src/vars.rs index 9d02ae9..872fe4f 100644 --- a/the_rewrite/src/vars.rs +++ b/the_rewrite/src/vars.rs @@ -35,12 +35,19 @@ impl<'a> VTable<'a> { } pub fn get(&'a self, id: String) -> Option>> { - self.0.get(&id) + match self.0.get(&id) { + Some(s) => Some(s.clone()), + None => None, + } } pub fn remove(&self, id: String) { self.0.remove(&id); } + + pub fn new() -> VTable<'a> { + VTable{0: HashMap::>::new()} + } } // returns a callback for the stdlib var export function with env_sync on or off