I need something like
fn foo() -> std::task::Poll<Result<(),std::io::Error>>{
...
}
fn bar() -> Result<u32,std::io::Error> {
foo()?;
/* do something else */
}
I quickly wrote something like the above, and then get suppised by “what? a Poll
is Try
?” in review.
Then I ask my self: what does it do when foo
is returning Pending
? Is it returning std::io::Error
with ErrorKind::WouldBlock
? A few moments I assemed that but finally I get back to the document and figured out the result will be a Pending
get ignored…
So it has to be
fn bar() -> Result<u32, std::io::Error> {
if let Poll::Pending = foo() {
Err(std::io::Error::from(std::io::ErrorKind::WouldBlock))
}
/* do something else */
}
Thinking how the Rust team will see from this kind of potential error…
At least, as a Result
value will warn you if you didn’t use it, the Poll
value should be the same, so I should be given a warning, right?