Skip to content

Instantly share code, notes, and snippets.

@subtly
Last active April 9, 2018 23:29
Show Gist options
  • Save subtly/f10d7592f402089b96f5b4e2837b6150 to your computer and use it in GitHub Desktop.
Save subtly/f10d7592f402089b96f5b4e2837b6150 to your computer and use it in GitHub Desktop.
rust learning puzzle #1
use std::thread;
use std::sync::mpsc::channel;
fn main() {
let (tx, rx) = channel();
// How to modify closure so only tx is captured? (without extra struct)
thread::spawn(move |tx| {
tx.send(String::from("hi")).unwrap();
});
println!("Got: {}", rx.recv().unwrap());
}
@subtly
Copy link
Author

subtly commented Apr 9, 2018

Capturing tx:

error[E0619]: the type of this value must be known in this context
 --> ticket.rs:9:9
  |
9 |         tx.send(String::from("hi")).unwrap();
  |         ^^

error: aborting due to previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment