如何为文件句柄获取tokio-io的async_read

时间:2017-06-01 17:39:27

标签: file asynchronous rust streaming rust-tokio

我想从文件句柄中流出行,我不知道如何满足File具有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,似乎File没有标记它具有非阻塞读取。我是否需要将File降级为raw_fd,然后在那里做点什么?

0 个答案:

没有答案