src/tools/std_channel_writer.rs: new StdChannelWriter helper class
This commit is contained in:
parent
51f0ab1e8b
commit
dcd033a53c
@ -28,6 +28,10 @@ pub mod ticket;
|
|||||||
pub mod timer;
|
pub mod timer;
|
||||||
pub mod tty;
|
pub mod tty;
|
||||||
pub mod wrapped_reader_stream;
|
pub mod wrapped_reader_stream;
|
||||||
|
|
||||||
|
mod std_channel_writer;
|
||||||
|
pub use std_channel_writer::*;
|
||||||
|
|
||||||
pub mod xattr;
|
pub mod xattr;
|
||||||
|
|
||||||
mod process_locker;
|
mod process_locker;
|
||||||
|
28
src/tools/std_channel_writer.rs
Normal file
28
src/tools/std_channel_writer.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
use std::sync::mpsc::SyncSender;
|
||||||
|
|
||||||
|
use failure::*;
|
||||||
|
|
||||||
|
/// Wrapper around SyncSender, which implements Write
|
||||||
|
///
|
||||||
|
/// Each write in translated into a send(Vec<u8>).
|
||||||
|
pub struct StdChannelWriter(SyncSender<Result<Vec<u8>, Error>>);
|
||||||
|
|
||||||
|
impl StdChannelWriter {
|
||||||
|
pub fn new(sender: SyncSender<Result<Vec<u8>, Error>>) -> Self {
|
||||||
|
Self(sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for StdChannelWriter {
|
||||||
|
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
|
||||||
|
self.0
|
||||||
|
.send(Ok(buf.to_vec()))
|
||||||
|
.map_err(proxmox::sys::error::io_err_other)
|
||||||
|
.and(Ok(buf.len()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> Result<(), std::io::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user