我想从文件句柄中流式传输行,但我不知道如何满足 aFile
具有的特征界限async_read
:
use std::fs::File;
use std::io::{ BufReader, BufRead };
use tokio_core::reactor::Handle;
use tokio_io::io::lines;
use tokio_io::AsyncRead;
struct DockerLog {
path: String
}
impl DockerLog {
pub fn new(path: String) -> DockerLog {
DockerLog {
path: path
}
}
pub fn read_lines(&self, handle: &Handle) {
let file : File = File::open(&self.path[..]).unwrap();
let l = lines(BufReader::new(file));
}
}
错误:
error[E0277]: the trait bound `std::fs::File: tokio_io::AsyncRead` is not satisfied
--> src/container/docker_logs.rs:20:17
|
20 | let l = lines(BufReader::new(file));
| ^^^^^ the trait `tokio_io::AsyncRead` is not implemented for `std::fs::File`
|
= note: required because of the requirements on the impl of `tokio_io::AsyncRead` for `std::io::BufReader<std::fs::File>`
= note: required by `tokio_io::io::lines`
查看AsyncRead
,似乎 aFile
没有标记它具有非阻塞读取。我需要降级File
到 araw_fd
然后在那里做点什么吗?