File 如何得到东京';文件句柄的异步读取

File 如何得到东京';文件句柄的异步读取,file,asynchronous,rust,streaming,rust-tokio,File,Asynchronous,Rust,Streaming,Rust Tokio,我想将行从文件句柄中流出来,但我不知道如何满足文件具有异步读取的特性界限: 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(p

我想将行从文件句柄中流出来,但我不知道如何满足
文件
具有
异步读取
的特性界限:

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]:特性绑定'std::fs::File:tokio_io::AsyncRead'不满足
-->src/container/docker_日志。rs:20:17
|
20 |让l=行(BufReader::new(file));
|^std::fs::File未实现特性“tokio::AsyncRead”`
|
=注:由于'std::io::BufReader'的'tokio_io::AsyncRead'impl上的要求,因此需要`
=注:`tokio_io::io::lines'需要`

查看,似乎
文件
没有标记它具有非阻塞读取。我是否需要将
文件
降级为
原始fd
,然后在那里做些什么?

通常,文件系统没有异步IO(或不可靠)。你在哪个站台?好的,我不知道。我只是针对Linux。从许多文件流式传输行的最佳方式是什么?听起来我应该为每个文件生成一个线程(通常不超过100个文件)。常见的解决方案是使用线程池和队列。如果您使用的是Tokio,我会首先考虑类似的内容。仅供参考,让file:file=file是多余的-我们不需要在这里编写老式Java
let file=file
就足够了。新的tokio发行版附带了一个tokio_fs机箱,最终支持异步文件,请参阅