TermRead read_line() conflicts with BufRead read_line()
Created by: zedzorander
This might be a compiler issue but... I am working on a network card game where I need to use a key event and a BufReader. I get an error message when I call the read_line() function on the BufReader. The compiler can't determine which read_line() function to call. Here's an example:
extern crate termion;
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin, BufRead, BufReader};
use std::fs::File;
fn main() {
let file = File::open("/etc/passwd").unwrap();
let reader = BufReader::new(&file);
let mut line = String::new();
reader.read_line(&line).unwrap();
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
for c in stdin.keys() {
match c.unwrap() {
Key::Char('q') => break,
Key::Char('x') => {
write!(stdout, "Key x\r\n").unwrap();
stdout.flush().unwrap();
},
_ => {}
}
stdout.flush().unwrap();
}
}
Here is the error message:
error[E0034]: multiple applicable items in scope
--> src/main.rs:14:12
|
14 | reader.read_line(&line).unwrap();
| ^^^^^^^^^ multiple `read_line` found
|
= note: candidate #1 is defined in an impl of the trait `std::io::BufRead` for the type `std::io::BufReader<_>`
= note: candidate #2 is defined in an impl of the trait `termion::input::TermRead` for the type `_`
The problem currently can be resolved by declaring reader this way:
let reader: &BufRead = &BufReader::new(&file);
let mut line = String::new();
reader.read_line(&line).unwrap();
But that's pretty ugly and was a bit of a pain to figure out.