std-method
Poll::map: transform a ready value
Map a completed value without changing the pending state. The callback runs only when a ready value is present. This is a data transformation, not an instruction to schedule the task. Expected stdout (not executed): Ready(14) Pending Common mistake: Expecting the mapping function to execute on Pending.
Formal Syntax & Structure
rust syntaxrust
p.map(f: impl FnOnce(T) -> U) -> Poll<U>Working Example
Example Snippetrust
fn main() { use std::task::Poll; let a = Poll::Ready(7).map(|n| n * 2); let b = Poll::<u32>::Pending.map(|n| n * 2); println!("{a:?} {b:?}");}