From 0dcc26ea2441c3540b6b4f77f4f0fa6cfc41b965 Mon Sep 17 00:00:00 2001 From: Jasper Schulz Date: Fri, 24 Mar 2017 10:57:00 +0100 Subject: [PATCH] Moved trait to . --- src/main.rs | 5 ++--- src/tracerunner.rs | 2 +- src/traits.rs | 31 +++++++++++++++++++++++++++++++ src/util.rs | 27 --------------------------- 4 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 src/traits.rs delete mode 100644 src/util.rs 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()); - } -}