Function thread_io::read::reader_init
source · pub fn reader_init<R, I, F, O, E>(
bufsize: usize,
queuelen: usize,
init_reader: I,
func: F
) -> Result<O, E>where
I: Send + FnOnce() -> Result<R, E>,
F: FnOnce(&mut Reader) -> Result<O, E>,
R: Read,
E: Send,
Expand description
Like reader()
, but the wrapped reader is initialized
in a closure (init_reader
) in the background thread. This allows using
readers that don’t implement Send
Example:
use thread_io::read::reader_init;
use std::io::{self, Read};
let mut input = io::stdin();
// StdinLock does not implement Send
reader_init(16, 2, || Ok(input.lock()), |rdr| {
let mut s = String::new();
let _ = rdr.read_to_string(&mut s).expect("read error");
// ...
Ok::<_, io::Error>(())
}).expect("read failed");