futures_util::compat

Trait Sink01CompatExt

source
pub trait Sink01CompatExt: Sink01 {
    // Provided method
    fn sink_compat(self) -> Compat01As03Sink<Self, Self::SinkItem>
       where Self: Sized { ... }
}
Available on crate features compat and sink only.
Expand description

Extension trait for futures 0.1 Sink

Provided Methods§

source

fn sink_compat(self) -> Compat01As03Sink<Self, Self::SinkItem>
where Self: Sized,

Converts a futures 0.1 Sink<SinkItem = T, SinkError = E> into a futures 0.3 Sink<T, Error = E>.

use futures::{sink::SinkExt, stream::StreamExt};
use futures_util::compat::{Stream01CompatExt, Sink01CompatExt};

let (tx, rx) = futures_01::unsync::mpsc::channel(1);
let (mut tx, mut rx) = (tx.sink_compat(), rx.compat());

tx.send(1).await.unwrap();
drop(tx);
assert_eq!(rx.next().await, Some(Ok(1)));
assert_eq!(rx.next().await, None);

Implementors§