Sha256: 7c6fbd10c782828793cbe1eb347ec776d99b185dad498e886f7161da76f76880

Contents?: true

Size: 859 Bytes

Versions: 25

Compression:

Stored size: 859 Bytes

Contents

use futures::future;
use futures::stream;
use futures_test::future::FutureTestExt;
use futures_test::{assert_stream_done, assert_stream_next, assert_stream_pending};

#[test]
fn unfold1() {
    let mut stream = stream::unfold(0, |state| {
        if state <= 2 {
            future::ready(Some((state * 2, state + 1))).pending_once()
        } else {
            future::ready(None).pending_once()
        }
    });

    // Creates the future with the closure
    // Not ready (delayed future)
    assert_stream_pending!(stream);
    // Future is ready, yields the item
    assert_stream_next!(stream, 0);

    // Repeat
    assert_stream_pending!(stream);
    assert_stream_next!(stream, 2);

    assert_stream_pending!(stream);
    assert_stream_next!(stream, 4);

    // No more items
    assert_stream_pending!(stream);
    assert_stream_done!(stream);
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
wasmtime-28.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/stream_unfold.rs
wasmtime-27.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/stream_unfold.rs
wasmtime-26.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/stream_unfold.rs
wasmtime-25.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-25.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-25.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-24.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-23.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-22.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-21.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-20.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-20.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-18.0.3 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-17.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-17.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-16.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-15.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-15.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/stream_unfold.rs
wasmtime-14.0.4 ./ext/cargo-vendor/futures-0.3.28/tests/stream_unfold.rs
wasmtime-14.0.3 ./ext/cargo-vendor/futures-0.3.28/tests/stream_unfold.rs