Created
September 15, 2019 09:52
-
-
Save rust-play/ec72783e21f5d0f1a6ac18f8939fbbb7 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 ::tokio::sync::mpsc; // 0.1.22 | |
struct Bar { | |
s: Option<String>, | |
sender: mpsc::Sender<Data>, | |
} | |
#[derive(Debug)] | |
struct Data { | |
s: String, | |
} | |
impl Bar { | |
fn send (self: &'_ mut Self) | |
{ | |
let data = Data { | |
s: self.s | |
.take() | |
.expect(".send() can only be called once!") | |
, | |
}; | |
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