Skip to content

Commit

Permalink
Moved trait ConvertingStack to trait.rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaheba committed Mar 24, 2017
1 parent ffd24e9 commit d74f9df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Rc<Func>>,
Expand Down
2 changes: 1 addition & 1 deletion src/tracerunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
31 changes: 31 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

pub mod vec {

pub trait ConvertingStack<T> {
fn pop_into<U>(&mut self) -> U where U: From<T>;

fn pop_2_into<U>(&mut self) -> (U, U) where U: From<T>;

fn push_from<U: Into<T>>(&mut self, val: U);

}

impl<T> ConvertingStack<T> for Vec<T> {
fn pop_into<U>(&mut self) -> U
where U: From<T>
{
self.pop().unwrap().into()
}

fn pop_2_into<U>(&mut self) -> (U, U)
where U: From<T>
{
(self.pop().unwrap().into(), self.pop().unwrap().into())
}

fn push_from<U: Into<T>>(&mut self, val: U) {
self.push(val.into());
}
}

}
27 changes: 0 additions & 27 deletions src/util.rs

This file was deleted.

0 comments on commit d74f9df

Please sign in to comment.