std-method
Poll<Result<T, E>>: map completion branches
A future can complete successfully or complete with an error. Mapping the success or error branch changes only that completed branch; Pending is preserved. These methods apply to the specialized Poll<Result<...>> shape. Expected stdout (not executed): Ready(Ok(4)) Ready(Err(3)) Common mistake: Treating an unfinished future as a failed operation.
Formal Syntax & Structure
rust syntaxrust
p.map_ok(f); p.map_err(f)Working Example
Example Snippetrust
fn main() { use std::task::Poll; let a: Poll<Result<u32, &str>> = Poll::Ready(Ok(3)); let b: Poll<Result<u32, &str>> = Poll::Ready(Err("bad")); println!("{:?}", a.map_ok(|n| n + 1)); println!("{:?}", b.map_err(|e| e.len()));}