]> git.proxmox.com Git - proxmox-backup.git/commitdiff
StdChannelWriter: avoid using anyhow::Error
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 25 Nov 2021 10:14:56 +0000 (11:14 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 25 Nov 2021 10:14:56 +0000 (11:14 +0100)
Use a generic implementation to allow different error types.

pbs-tools/src/sync/std_channel_writer.rs

index eb2170599f92e3dca653fd3a4a29b27816451d29..c5131a127004650acb78650300619b6dfde2575b 100644 (file)
@@ -1,24 +1,23 @@
 use std::io::Write;
 use std::sync::mpsc::SyncSender;
-
-use anyhow::{Error};
+use std::string::ToString;
 
 /// Wrapper around SyncSender, which implements Write
 ///
 /// Each write in translated into a send(Vec<u8>).
-pub struct StdChannelWriter(SyncSender<Result<Vec<u8>, Error>>);
+pub struct StdChannelWriter<E>(SyncSender<Result<Vec<u8>, E>>);
 
-impl StdChannelWriter {
-    pub fn new(sender: SyncSender<Result<Vec<u8>, Error>>) -> Self {
+impl <E: ToString> StdChannelWriter<E> {
+    pub fn new(sender: SyncSender<Result<Vec<u8>, E>>) -> Self {
         Self(sender)
     }
 }
 
-impl Write for StdChannelWriter {
+impl <E: ToString> Write for StdChannelWriter<E> {
     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)
+            .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err.to_string()))
             .and(Ok(buf.len()))
     }