January 2019
Intermediate to advanced
520 pages
14h 32m
English
As mentioned previously, you can use a channel to send data with Sink from different places and at any time. Look at the following example:
fn alt_udp_echo() -> Result<(), Error> { let from = "0.0.0.0:12345".parse()?; let socket = UdpSocket::bind(&from)?; let framed = UdpFramed::new(socket, LinesCodec::new()); let (sink, stream) = framed.split(); let (tx, rx) = mpsc::channel(16); let rx = rx.map_err(|_| other("can't take a message")) .fold(sink, |sink, frame| { sink.send(frame) }); let process = stream.and_then(move |args| { tx.clone() .send(args) .map(drop) .map_err(other) }).collect(); let execute_all = future::join_all(vec![ to_box(rx), to_box(process), ]).map(drop); Ok(tokio::run(execute_all)) ...Read now
Unlock full access