Skip to content
Snippets Groups Projects
Commit 878251d3 authored by Per Lindgren's avatar Per Lindgren
Browse files

compiles

parent 4d7a9016
No related branches found
No related tags found
No related merge requests found
......@@ -79,30 +79,23 @@ trait Dispatch {
fn dispatch(&mut self);
}
// struct MsgQ<'a, T>(VecDeque<&'a Mutex<T>>)
// where
// T: 'a + Dispatch;
// impl<'a, T> Dispatch for MsgQ<'a, T>
// where
// T: 'a + Dispatch,
// {
// fn dispatch(&mut self) {}
// }
// impl<'a, T> Dispatch for &'a Vec<Mutex<T>> {
// fn dispatch(&mut self) {}
// }
struct MsgQ<'a>(VecDeque<&'a mut Dispatch>);
struct MsgQ<'a>(VecDeque<&'a Dispatch>);
impl<'a> Dispatch for MsgQ<'a> {
fn dispatch(&mut self) {
println!("MsgQ Dispatch");
// impl<'a, T> Dispatch for MsgQ<'a, T> {
// fn dispatch(&mut self) {}
// }
struct Msg<T>(Mutex<T>, Box<FnMut(T) -> ()>);
self.0.pop_front().unwrap().dispatch();
}
}
struct Msg<T>(Mutex<T>, Box<FnMut(&mut T) -> ()>);
impl<T> Dispatch for Msg<T> {
fn dispatch(&mut self) {}
fn dispatch(&mut self) {
println!("Msg Dispatch");
let mut o = self.0.lock().unwrap();
self.1(&mut *o);
}
}
impl<T> Dispatch for Mutex<T> {
......@@ -145,21 +138,18 @@ fn main() {
)));
let m = Mutex::new(0);
let m2 = Mutex::new(0.0);
let mut q = MsgQ {
0: VecDeque::new(),
};
q.0.push_back(&m);
q.0.push_back(&m2);
let mut q = MsgQ { 0: VecDeque::new() };
let c1 = |o: &mut i32| println!("hello {}", o);
let c1 = |o| println!("hello {}", o);
let msg = Msg {
let mut msg = Msg {
0: m,
1: Box::new(c1),
};
q.0.dispatch();
q.0.push_back(&mut msg);
q.dispatch();
//q.0.push_back(&(m, c1));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment