]>
git.proxmox.com Git - proxmox-backup.git/blob - pbs-tools/src/sync/std_channel_writer.rs
2 use std
::sync
::mpsc
::SyncSender
;
3 use std
::string
::ToString
;
5 /// Wrapper around SyncSender, which implements Write
7 /// Each write in translated into a send(Vec<u8>).
8 pub struct StdChannelWriter
<E
>(SyncSender
<Result
<Vec
<u8>, E
>>);
10 impl <E
: ToString
> StdChannelWriter
<E
> {
11 pub fn new(sender
: SyncSender
<Result
<Vec
<u8>, E
>>) -> Self {
16 impl <E
: ToString
> Write
for StdChannelWriter
<E
> {
17 fn write(&mut self, buf
: &[u8]) -> Result
<usize, std
::io
::Error
> {
19 .send(Ok(buf
.to_vec()))
20 .map_err(|err
| std
::io
::Error
::new(std
::io
::ErrorKind
::Other
, err
.to_string()))
24 fn flush(&mut self) -> Result
<(), std
::io
::Error
> {