dpc / mioco.pre-0.9

Scalable, coroutine-based, asynchronous IO handling library for Rust programming language. (aka MIO COroutines).
Mozilla Public License 2.0
457 stars 30 forks source link

select! on struct fields fails to compile. #119

Closed lhallam closed 8 years ago

lhallam commented 8 years ago

Here's a small test case:

#[macro_use] extern crate mioco;
use mioco::sync::mpsc::*;

struct Foo{
    rx: Receiver<String>,
}

impl Foo{
    pub fn run(self){
        select!(
            self.rx:r => {
                println!("{}",rx.recv().unwrap());
            },);
    }
}

fn main(){
    mioco::start(||{
        let (sx,rx) = channel();
        let foo = Foo{ rx: rx };
        mioco::spawn(move || foo.run());
        sx.send("Hello world!".to_owned());
        mioco::sleep_ms(100);
    });
}

On the latest rust nightly this fails to compile:

➜  select_test git:(master) ✗ cargo build            
   Compiling select_test v0.1.0 (file:///home/xalri/select_test)
<mioco macros>:30:12: 30:13 error: expected ident, found @
<mioco macros>:30 select ! ( @ wrap1 $ ( $ tail ) * ) ; let ret = mioco:: select_wait (  ) ;
                             ^
error: Could not compile `select_test`

The result is the same if run takes &mut self. If you add let rx = self.rx and use this in the select, it works as expected. I'm quite new to both mioco and rust itsself, so sorry if I've missed anything ^^

dpc commented 8 years ago

It's a problem with a select! macro, I guess. I'll look into it. Thanks for reporting it! For now, you'll have to use a workaround (let rx = self.rx). Or if you feel adventurous, you can try to improve the macro yourself. :)

dpc commented 8 years ago

Should be fixed in e15e84c5f56447a7741c06cd23ec5f58b598580f.