Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 10, 2020 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/a65d00b78bf20e7492a4c3dcda46e1bb to your computer and use it in GitHub Desktop.
Save rust-play/a65d00b78bf20e7492a4c3dcda46e1bb to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::task::Poll;
use std::io::{Error, ErrorKind, Result};
fn err() -> Result<()> {
Err(Error::new(ErrorKind::Other, "error"))
}
fn main() {
println!("{:?}", test(Poll::Ready(err())));
println!("{:?}", test2(err()));
// println!("{:?}", test3(err()));
}
fn test(p: Poll<Result<()>>) -> Poll<Option<Result<()>>> {
match p {
Poll::Ready(v) => v,
Poll::Pending => return Poll::Pending,
}?;
Poll::Ready(Some(Ok(())))
}
fn test2(r: Result<()>) -> Option<Result<()>> {
match test(Poll::Ready(r)) {
Poll::Ready(v) => v,
_ => None,
}
}
// fn test3(r: Result<()>) -> Option<Result<()>> {
// r?;
// Some(Ok(()))
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment