How to get tokio-io's async_read for a File handle

Viewed 2221

I want to stream lines out of a file handle and I do not know how to satisfy the trait bound that a File has 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));

    }
}

The error:

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`

Looking over the AsyncRead, it seems like a File doesn't mark that it has non-blocking reads. Do I need to downgrade the File to a raw_fd and then do something there?

0 Answers
Related