I started with an example for EventLoop from the mio web page and added the main function:
extern crate mio; use std::thread; use mio::{EventLoop, Handler}; struct MyHandler; impl Handler for MyHandler { type Timeout = (); type Message = u32; fn notify(&mut self, event_loop: &mut EventLoop<MyHandler>, msg: u32) { assert_eq!(msg, 123); event_loop.shutdown(); } } fn main() { let mut event_loop = EventLoop::new().unwrap(); let sender = event_loop.channel();
Then I had the idea to move the send stream to a separate function "foo" and began to wonder what type was passed:
extern crate mio; use std::thread; use mio::{EventLoop, Handler}; struct MyHandler; impl Handler for MyHandler { type Timeout = (); type Message = u32; fn notify(&mut self, event_loop: &mut EventLoop<MyHandler>, msg: u32) { assert_eq!(msg, 123); event_loop.shutdown(); } } fn foo(s: &?) { let sender = s.clone();
So, I will let the compiler tell me the type:
fn foo(s: &String) { ...
causes an error:
error: mismatched types: expected `&collections::string::String`, found `&mio::event_loop::Sender<_>`
Ok, nice, but replacing &String with &mio::event_loop::Sender<u32> raises an error:
error: struct `Sender` is private fn foo(s: &mio::event_loop::Sender<u32>) { ^
Hm, it looks like a dead end, so I thought to skip event_loop:
fn foo(s: &mio::event_loop::EventLoop<u32>) { let sender = s.channel().clone(); ... fn main() { ... foo(&event_loop); ...
but this causes an error:
error: the trait `mio::handler::Handler` is not implemented for the type `u32` [E0277] src/main.rs:18 fn foo(s: &mio::event_loop::EventLoop<u32>) {
which bothers me completely.
In particular. C / C ++ I would just pass a pointer to either EventLop or Sender.
What is Rusta trying to tell me here? How to make it work in Rust?
Environment: rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14), mio ββ0.3.5