[−][src]Function thread_io::write::writer_finish
pub fn writer_finish<W, F, O, F2, O2, E>(
bufsize: usize,
queuelen: usize,
writer: W,
func: F,
finish: F2
) -> Result<(O, O2), E> where
F: FnOnce(&mut Writer) -> Result<O, E>,
W: Write + Send,
F2: Send + FnOnce(W) -> O2,
O2: Send,
E: Send + From<Error>,
Like writer
, but accepts another closure taking the wrapped writer by
value before it goes out of scope (and there is no error).
Useful for performing finalizing actions or returning the wrapped writer to
the main thread (if it implements Send
).
The output values of func
and the finish
closure are returned in a
tuple.
Example:
use thread_io::write::writer_finish; use std::io::Write; let text = b"The quick brown fox jumps over the lazy dog"; let mut output = vec![]; // `output` is moved to background thread let (_, output) = writer_finish(16, 2, output, |out| out.write_all(&text[..]), |out| out // output is returned to main thread ).expect("write failed"); assert_eq!(&output[..], &text[..]);