我想实现Read结构的特征,以便在 a 中使用它BufReader来传递给库。该库使用 aBufReader作为输入,因为它应该与Stdin实现Read.
use std::error::Error;
use std::io::Read;
pub struct Test {
counter: u8,
}
impl Test {
pub fn new() -> Test {
Test { counter: 0 }
}
}
impl Iterator for Test {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
if self.counter < 2 {
self.counter += 1;
return Some("String".to_string());
}
None
}
}
impl Read for Test {
fn read(&mut self, buf: &mut …Run Code Online (Sandbox Code Playgroud) rust ×1