1 个不稳定版本

使用旧的 Rust 2015

0.1.0 2018年10月18日

#117#closures

BSD-2-Clause 协议

5KB
98

GitHub license Crates.io

此实现通过调用函数来生成数据,实现了 Read 特性。

请参阅 API 文档

导入包

read_with="0.1"

示例

let mut output = vec!();
let many_strings = ["one", "two", "three"];
let mut pos = 0;

std::io::copy(
    &mut ReadWith::new(
        ||
        {
            if pos == many_strings.len() { return None; }
            let o = many_strings[pos];
            pos+=1;
            Some(o)
        }
    ),
    &mut output,
).unwrap();
assert_eq!("onetwothree", str::from_utf8(&output).unwrap());

lib.rs:

创建一个从函数中增量获取数据的 Read 对象。

这允许您从向量数组中读取或创建从数据库或其他数据源获取块的读取器。

示例

let many_strings = ["one", "two", "three"];
let mut pos = 0;
std::io::copy(
    &mut read_with::ReadWith::new(
        ||
        {
            if pos == many_strings.len() { return None; }
            let o = many_strings[pos];
            pos+=1;
            Some(o)
        }
    ),
    &mut std::io::stdout(),
).unwrap();

无运行时依赖项