You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#![feature( if_let )]use std::io::BufReader;fnmain(){let text = b"the quick brown fox jumps over";letmut 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 ];iflet[ 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())