Created
September 15, 2019 09:58
-
-
Save rust-play/a44d3e7107a4277f8a45ee68fb501432 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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::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