Closed
Description
#![feature( if_let )]
use std::io::BufReader;
fn main() {
let text = b"the
quick
brown
fox
jumps
over";
let mut reader = BufReader::new(text);
let (tx, rx) = channel();
spawn(proc() {
for line in reader.lines() {
let line = line.unwrap();
let line = line.trim_chars(|c: char| c.is_whitespace());
let list = vec![ line ];
if let [ word ] = &*list {
tx.send(word);
}
}
});
for word in rx.iter() {
println!("{}", word);
}
}
One would expect the output to be
the
quick
brown
fox
jumps
over
But the actual output is:
the
overs
overs
ove
overs
over
It looks like the memory location at word is overwritten.
The program will behave correctly if word is deep copied before being sent, i.e. changing tx.send(word) to tx.send(word.to_string())
Metadata
Metadata
Assignees
Labels
No labels