I have an async fn that returns a value I pass to Tokio's tokio::spawn()
that compiled, but had a bug. Trying to fix the bug by modifying a statement in the function caused the program to not compile anymore. I'm using the alpha version of Tokio (the one that supports async/.await). The error is:
error[E0308]: mismatched types
--> src/wormhole.rs:55:9
|
55 | tokio::spawn(session);
| ^^^^^^^^^^^^ one type is more general than the other
|
= note: expected typetokio_io::io::shutdown::Shutdown<'_, wormhole::appendmsg_session::ClonedWriter<'_>>
found typetokio_io::io::shutdown::Shutdown<'_, wormhole::appendmsg_session::ClonedWriter<'_>>
What it found and what it expected look identical. The gist of what I changed was altering the types of the futures passed to a call to try_join()
, which is awaited inside that function. It used to be:
try_join(
DecryptingReader::new(remote_header, &mut client_reader).copy(&mut server_writer),
EncryptingReader::new(*header, &mut server_reader).copy(&mut client_writer),
)
.await?;
The types of those arguments are:
tokio_io::io::copy::Copy<'_, appendmsg_session::DecryptingReader<'_>, tokio_net::tcp::split::WriteHalf<'_>>
tokio_io::io::copy::Copy<'_, appendmsg_session::EncryptingReader<'_>, tokio_net::tcp::split::WriteHalf<'_>>
In the not-compiling version, the arguments are more complex, because I tacked on a .then
combinator:
try_join(
DecryptingReader::new(remote_header, &mut client_reader)
.copy(&mut server_writer)
.then(|r| {
reader_finish(r);
server_writer_to_close.shutdown()
}),
EncryptingReader::new(*header, &mut server_reader)
.copy(&mut client_writer)
.then(|r| {
reader_finish(r);
client_writer_to_close.shutdown()
}),
)
.await?;
The types of the arguments are now:
futures_util::future::then::Then<tokio_io::io::copy::Copy<'_, appendmsg_session::DecryptingReader<'_>, appendmsg_session::ClonedWriter<'_>>, tokio_io::io::shutdown::Shutdown<'_, appendmsg_session::ClonedWriter<'_>>, [closure@src/appendmsg_session.rs:49:19: 52:14 server_writer_to_close:_]>`
futures_util::future::then::Then<tokio_io::io::copy::Copy<'_, appendmsg_session::EncryptingReader<'_>, appendmsg_session::ClonedWriter<'_>>, tokio_io::io::shutdown::Shutdown<'_, appendmsg_session::ClonedWriter<'_>>, [closure@src/appendmsg_session.rs:56:19: 59:14 client_writer_to_close:_]>`
What does that error mean? I'm not sure how to go about resolving this one.