move more tools for the client into subcrates

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2021-07-15 12:15:50 +02:00
parent 9eb784076c
commit 4805edc4ec
29 changed files with 115 additions and 102 deletions

View File

@ -0,0 +1,2 @@
mod std_channel_writer;
pub use std_channel_writer::StdChannelWriter;

View File

@ -0,0 +1,28 @@
use std::io::Write;
use std::sync::mpsc::SyncSender;
use anyhow::{Error};
/// 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(())
}
}