Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Tokio_util nested compat?
crate tokio_util provide compat module that allow interop between futures AsyncRead
, AsyncWrite
and tokio AsyncRead
, AsyncWrite
by using one of bridging trait such as FuturesAsyncReadCompatExt
.
In my use case, to make my code generic, my function look like this:
async fn transform_something<S: futures::io::AsyncRead>(stream: S> -> SomeStruct {
SomeStruct::new(stream.compat()) // <- This struct need tokio::io::AsyncRead
}
At some call site, it call this transform_something
like this:
// the tokio_stream impl trait tokio::io::AsyncRead so it need compat
let transform_stream = transform_something(tokio_stream.compat());
The actual type inside transform_stream that do the work end up with nested Compat<Compat<>>
.
I'm not sure will there by any performance penalty from this indirection ?
Is there any better way to do this kind of interop to prevent deep nested Compat ?
1 post - 1 participant
🏷️ rust_feed