You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: scan.rs
    path of file: ./repos/phaser/phaser/vendor/futures-util/src/stream/stream
    
    the code of the file until where you have to start completion: use core::fmt;
use core::pin::Pin;
use futures_core::future::Future;
use futures_core::ready;
use futures_core::stream::{FusedStream, Stream};
use futures_core::task::{Context, Poll};
#[cfg(feature = "sink")]
use futures_sink::Sink;
use pin_project_lite::pin_project;

struct StateFn<S, F> {
    state: S,
    f: F,
}

pin_project! {
    /// Stream for the [`scan`](super::StreamExt::scan) method.
    #[must_use = "streams do nothing unless polled"]
    pub struct S
    
    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<B>> {
        if self.is_done_taking() {
            return Poll::Ready(None);
        }

        let mut this = self.project();

        Poll::Ready(loop {
            if let Some(fut) = this.future.as_mut().as_pin_mut() {
                let item = ready!(fut.poll(cx));
                this.future.set(None);

                if item.is_none() {
                    *this.state_f = None;
                }

                break item;
            } else if let Some(item) = ready!(this.stream.as_mut().poll_next(cx)) {
                let state_f = this.state_f.as_mut().unwrap();
                this.future.set(Some((state_f.f)(&mut state_f.state, item)))
            } else {
                break None;
            }
        })
    }