How to get tokio-io async_read for a File descriptor
I want to pass lines from a file descriptor and I have no idea how to satisfy the heck attachment that 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));
}
}
Mistake:
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 back at AsyncRead
, it seems that File
doesn't mean it has non-blocking reads. Do I need to downgrade File
to raw_fd
and then do something?
+3
source to share
No one has answered this question yet
Check out similar questions: