Function futures::stream::poll_fn [−][src]
pub fn poll_fn<T, E, F>(f: F) -> PollFn<F> where
F: FnMut() -> Poll<Option<T>, E>,
Expand description
Creates a new stream wrapping around a function returning Poll
.
Polling the returned stream delegates to the wrapped function.
Examples
use futures::stream::poll_fn; use futures::{Async, Poll}; let mut counter = 1usize; let read_stream = poll_fn(move || -> Poll<Option<String>, std::io::Error> { if counter == 0 { return Ok(Async::Ready(None)); } counter -= 1; Ok(Async::Ready(Some("Hello, World!".to_owned()))) });