Last active
August 29, 2015 13:57
-
-
Save quux00/9560018 to your computer and use it in GitHub Desktop.
select! issue in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::Timer; | |
struct A { | |
c: Sender<~str>, | |
p: Receiver<~str> | |
} | |
fn main() { | |
compiles(); | |
does_not_compile(); | |
} | |
/* | |
<std macros>:7:37: 7:41 error: mismatched types: expected `&std::comm::Receiver<<generic #45>>` but found `&&std::comm::Receiver<~str>` (expected struct std::comm::Receiver but found &-ptr) | |
<std macros>:7 $( let mut $rx = sel.handle(&$rx); )+ | |
^~~~ | |
<std macros>:1:1: 15:2 note: in expansion of select! | |
selfport.rs:21:5: 24:7 note: expansion site | |
selfport.rs:22:42: 22:43 error: cannot determine a type for this bounded type parameter: unconstrained type | |
selfport.rs:22 s = p.recv() => println!("{:s}", s), // error: no rules expected the token `.` | |
*/ | |
fn also_does_not_compile() { | |
let (ch, pt): (Sender<~str>, Receiver<~str>) = channel(); | |
let a = A{c: ch, p: pt}; | |
let mut timer = Timer::new().unwrap(); | |
let timeout = timer.oneshot(1000); | |
let p = &a.p; | |
select! ( | |
s = p.recv() => println!("{:s}", s), // see error above | |
() = timeout.recv() => println!("time out!") | |
); | |
} | |
fn does_not_compile() { | |
let (ch, pt): (Sender<~str>, Receiver<~str>) = channel(); | |
let a = A{c: ch, p: pt}; | |
let mut timer = Timer::new().unwrap(); | |
let timeout = timer.oneshot(1000); | |
select! ( | |
s = a.p.recv() => println!("{:s}", s), // error: no rules expected the token `.` | |
() = timeout.recv() => println!("time out!") | |
); | |
} | |
fn compiles() { | |
let (ch, pt): (Sender<~str>, Receiver<~str>) = channel(); | |
// let a = A{c: ch, p: pt}; | |
let mut timer = Timer::new().unwrap(); | |
let timeout = timer.oneshot(1000); | |
select! ( | |
s = pt.recv() => println!("{:s}", s), | |
() = timeout.recv() => println!("time out!") | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment