-
-
Save rust-play/a65d00b78bf20e7492a4c3dcda46e1bb to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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