将结果的迭代器转换为结果<vec <_>&gt;

时间:2018-05-13 10:05:12

标签: rust

如何将iterator Result转换为Result向量?

作为一个例子,假设我想转换从Bytes特征可获得的Read迭代器:

use std::io::{Read, Result};

use std::fs::File;


fn main() {
    let f = File::open("some-file").unwrap();
    let bytes = f.bytes();

    let byte_vector: Result<Vec<u8>> = read_bytes(bytes);
}

fn read_bytes<I: Iterator<Item=Result<u8>>>(bytes: I) -> Result<Vec<u8>> {
    unimplemented!();
}

0 个答案:

没有答案