diff --git a/src/main.rs b/src/main.rs index bb6a869..414a4b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,9 +22,8 @@ use recovery::{Guard, FrameInfo}; mod tracerunner; use tracerunner::Runner; -mod util; -use util::ConvertingStack; - +mod traits; +use traits::vec::ConvertingStack; pub struct Module { funcs: BTreeMap>, diff --git a/src/tracerunner.rs b/src/tracerunner.rs index 01d073e..c614b7a 100644 --- a/src/tracerunner.rs +++ b/src/tracerunner.rs @@ -4,7 +4,7 @@ use super::{TraceInstruction, Comp, Value, Interpreter, CallFrame, Func}; use recovery::Guard; use kaktus::PushPop; -use util::ConvertingStack; +use traits::vec::ConvertingStack; pub struct Runner<'a, 'b: 'a> { diff --git a/src/traits.rs b/src/traits.rs new file mode 100644 index 0000000..b115885 --- /dev/null +++ b/src/traits.rs @@ -0,0 +1,31 @@ + +pub mod vec { + + pub trait ConvertingStack { + fn pop_into(&mut self) -> U where U: From; + + fn pop_2_into(&mut self) -> (U, U) where U: From; + + fn push_from>(&mut self, val: U); + + } + + impl ConvertingStack for Vec { + fn pop_into(&mut self) -> U + where U: From + { + self.pop().unwrap().into() + } + + fn pop_2_into(&mut self) -> (U, U) + where U: From + { + (self.pop().unwrap().into(), self.pop().unwrap().into()) + } + + fn push_from>(&mut self, val: U) { + self.push(val.into()); + } + } + +} diff --git a/src/util.rs b/src/util.rs deleted file mode 100644 index f1a843c..0000000 --- a/src/util.rs +++ /dev/null @@ -1,27 +0,0 @@ - - -pub trait ConvertingStack { - fn pop_into(&mut self) -> U where U: From; - - fn pop_2_into(&mut self) -> (U, U) where U: From; - - fn push_from>(&mut self, val: U); -} - -impl ConvertingStack for Vec { - fn pop_into(&mut self) -> U - where U: From - { - self.pop().unwrap().into() - } - - fn pop_2_into(&mut self) -> (U, U) - where U: From - { - (self.pop().unwrap().into(), self.pop().unwrap().into()) - } - - fn push_from>(&mut self, val: U) { - self.push(val.into()); - } -}