Created
April 30, 2014 02:13
-
-
Save brushbox/5554d24524cac23dae78 to your computer and use it in GitHub Desktop.
Having trouble with match and enums in rust.
This file contains 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::comm::channel; | |
use std::io::timer::sleep; | |
use std::sync::deque::BufferPool; | |
use std::sync::deque::Stolen; | |
fn main() { | |
let (tx, rx) = channel(); | |
let mut pool = BufferPool::new(); | |
let (worker, stealer) = pool.deque(); | |
spawn(proc() { | |
for i in range(0, 3) { | |
let st = stealer.clone(); | |
spawn(proc() { | |
let mut st = st; | |
loop { | |
match st.steal() { | |
//Data((proc_id, val)) => { println!("Stealer {} got {} from Process {}", i, val, proc_id) } | |
Empty => { sleep(1000) } | |
Abort => { println!("Aborted") } | |
_ => { println!("Stealer {} got something it doesn't know what to do with", i) } | |
} | |
} | |
}); | |
} | |
let mut worker = worker; | |
loop { | |
let (id, val): (int, int) = rx.recv(); | |
worker.push((id, val)); | |
println!("Process {} sent {}", id, val); | |
} | |
}); | |
for i in range(0, 3) { | |
let tx = tx.clone(); | |
spawn(proc() { | |
for x in range(0, 10) { | |
tx.send((i, x)); | |
sleep(100u64); | |
} | |
}); | |
} | |
sleep(10000u64); | |
} |
This file contains 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
channel.rs:18:25: 18:29 error: unresolved enum variant, struct or const `Data` | |
channel.rs:18 Data((proc_id, val)) => { println!("Stealer {} got {} from Process {}", i, val, proc_id) } | |
^~~~ | |
error: aborting due to previous error |
This file contains 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
channel.rs:20:25: 20:30 error: unreachable pattern | |
channel.rs:20 Abort => { println!("Aborted") } | |
^~~~~ | |
channel.rs:21:25: 21:26 error: unreachable pattern | |
channel.rs:21 _ => { println!("Stealer {} got something it doesn't know what to do with", i) } | |
^ | |
error: aborting due to 2 previous errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment