]>
git.proxmox.com Git - proxmox-backup.git/blob - src/tools/tokio_writer_adapter.rs
3 use tokio
::task
::block_in_place
;
5 /// Wrapper around a writer which implements Write
7 /// wraps each write with a 'block_in_place' so that
8 /// any (blocking) writer can be safely used in async context in a
10 pub struct TokioWriterAdapter
<W
: Write
>(W
);
12 impl<W
: Write
> TokioWriterAdapter
<W
> {
13 pub fn new(writer
: W
) -> Self {
18 impl<W
: Write
> Write
for TokioWriterAdapter
<W
> {
19 fn write(&mut self, buf
: &[u8]) -> Result
<usize, std
::io
::Error
> {
20 block_in_place(|| self.0.write(buf
))
23 fn flush(&mut self) -> Result
<(), std
::io
::Error
> {
24 block_in_place(|| self.0.flush
())