Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created September 15, 2019 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/a44d3e7107a4277f8a45ee68fb501432 to your computer and use it in GitHub Desktop.
Save rust-play/a44d3e7107a4277f8a45ee68fb501432 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use ::std::sync::Arc;
use ::tokio::sync::mpsc; // 0.1.22
struct Bar {
s: Arc<str>,
sender: mpsc::Sender<Data>,
}
#[derive(Debug)]
struct Data {
s: Arc<str>,
}
impl Bar {
fn send (self: &'_ mut Self)
{
let data = Data {
s: self.s.clone(),
};
self.sender
.try_send(data)
.expect("Failed to send to channel")
;
}
}
fn main ()
{
let (sender, _receiver) = mpsc::channel::<Data>(100);
let mut b = Bar {
s: String::from("hello").into(),
sender,
};
b.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment