Sha256: 930ce8ab5562c2013f4a75cdf717e41a7f8f3cbad6bae7bde68f0cfa3f2fd80a

Contents?: true

Size: 859 Bytes

Versions: 30

Compression:

Stored size: 859 Bytes

Contents

#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations

use tempfile::NamedTempFile;
use tokio::fs::File;
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio_test::assert_ok;

#[tokio::test]
async fn fill_buf_file() {
    let file = NamedTempFile::new().unwrap();

    assert_ok!(std::fs::write(file.path(), b"hello"));

    let file = assert_ok!(File::open(file.path()).await);
    let mut file = BufReader::new(file);

    let mut contents = Vec::new();

    loop {
        let consumed = {
            let buffer = assert_ok!(file.fill_buf().await);
            if buffer.is_empty() {
                break;
            }
            contents.extend_from_slice(buffer);
            buffer.len()
        };

        file.consume(consumed);
    }

    assert_eq!(contents, b"hello");
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/tokio-1.43.0/tests/io_fill_buf.rs
wasmtime-28.0.0 ./ext/cargo-vendor/tokio-1.43.0/tests/io_fill_buf.rs
wasmtime-27.0.0 ./ext/cargo-vendor/tokio-1.41.1/tests/io_fill_buf.rs
wasmtime-26.0.0 ./ext/cargo-vendor/tokio-1.41.0/tests/io_fill_buf.rs
wasmtime-25.0.2 ./ext/cargo-vendor/tokio-1.40.0/tests/io_fill_buf.rs
wasmtime-25.0.1 ./ext/cargo-vendor/tokio-1.39.3/tests/io_fill_buf.rs
wasmtime-25.0.0 ./ext/cargo-vendor/tokio-1.39.3/tests/io_fill_buf.rs
wasmtime-24.0.0 ./ext/cargo-vendor/tokio-1.39.3/tests/io_fill_buf.rs
wasmtime-23.0.2 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-22.0.0 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-21.0.1 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-20.0.2 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-20.0.0 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-18.0.3 ./ext/cargo-vendor/tokio-1.36.0/tests/io_fill_buf.rs
wasmtime-17.0.1 ./ext/cargo-vendor/tokio-1.35.1/tests/io_fill_buf.rs
wasmtime-17.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/io_fill_buf.rs
wasmtime-16.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/io_fill_buf.rs
wasmtime-15.0.1 ./ext/cargo-vendor/tokio-1.35.1/tests/io_fill_buf.rs
wasmtime-15.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/io_fill_buf.rs
wasmtime-14.0.4 ./ext/cargo-vendor/tokio-1.33.0/tests/io_fill_buf.rs