From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox 1/2] proxmox-compression: make ZstdEncoder stream a bit more generic
Date: Tue, 31 May 2022 13:17:20 +0200 [thread overview]
Message-ID: <20220531111726.2972022-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20220531111726.2972022-1-d.csapak@proxmox.com>
by not requiring the 'anyhow::Error' type from the source, but only
that it implements 'Into<Error>'. This way, we can also accept a stream
that produces e.g. an io::Error
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-compression/src/zstd.rs | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/proxmox-compression/src/zstd.rs b/proxmox-compression/src/zstd.rs
index d9e5826..3d4b2ab 100644
--- a/proxmox-compression/src/zstd.rs
+++ b/proxmox-compression/src/zstd.rs
@@ -32,10 +32,11 @@ pub struct ZstdEncoder<'a, T> {
state: EncoderState,
}
-impl<'a, T, O> ZstdEncoder<'a, T>
+impl<'a, T, O, E> ZstdEncoder<'a, T>
where
- T: Stream<Item = Result<O, Error>> + Unpin,
+ T: Stream<Item = Result<O, E>> + Unpin,
O: Into<Bytes>,
+ E: Into<Error>,
{
/// Returns a new [ZstdEncoder] with default level 3
pub fn new(inner: T) -> Result<Self, io::Error> {
@@ -79,10 +80,11 @@ impl<'a, T> ZstdEncoder<'a, T> {
}
}
-impl<'a, T, O> Stream for ZstdEncoder<'a, T>
+impl<'a, T, O, E> Stream for ZstdEncoder<'a, T>
where
- T: Stream<Item = Result<O, Error>> + Unpin,
+ T: Stream<Item = Result<O, E>> + Unpin,
O: Into<Bytes>,
+ E: Into<Error>,
{
type Item = Result<Bytes, Error>;
@@ -93,7 +95,10 @@ where
match this.state {
EncoderState::Reading => {
if let Some(res) = ready!(Pin::new(&mut this.inner).poll_next(cx)) {
- let buf = res?;
+ let buf = match res {
+ Ok(buf) => buf,
+ Err(err) => return Poll::Ready(Some(Err(err.into()))),
+ };
this.input_buffer = buf.into();
this.state = EncoderState::Writing;
} else {
--
2.30.2
WARNING: multiple messages have this Message-ID
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 1/2] proxmox-compression: make ZstdEncoder stream a bit more generic
Date: Tue, 31 May 2022 13:17:20 +0200 [thread overview]
Message-ID: <20220531111726.2972022-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20220531111726.2972022-1-d.csapak@proxmox.com>
by not requiring the 'anyhow::Error' type from the source, but only
that it implements 'Into<Error>'. This way, we can also accept a stream
that produces e.g. an io::Error
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-compression/src/zstd.rs | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/proxmox-compression/src/zstd.rs b/proxmox-compression/src/zstd.rs
index d9e5826..3d4b2ab 100644
--- a/proxmox-compression/src/zstd.rs
+++ b/proxmox-compression/src/zstd.rs
@@ -32,10 +32,11 @@ pub struct ZstdEncoder<'a, T> {
state: EncoderState,
}
-impl<'a, T, O> ZstdEncoder<'a, T>
+impl<'a, T, O, E> ZstdEncoder<'a, T>
where
- T: Stream<Item = Result<O, Error>> + Unpin,
+ T: Stream<Item = Result<O, E>> + Unpin,
O: Into<Bytes>,
+ E: Into<Error>,
{
/// Returns a new [ZstdEncoder] with default level 3
pub fn new(inner: T) -> Result<Self, io::Error> {
@@ -79,10 +80,11 @@ impl<'a, T> ZstdEncoder<'a, T> {
}
}
-impl<'a, T, O> Stream for ZstdEncoder<'a, T>
+impl<'a, T, O, E> Stream for ZstdEncoder<'a, T>
where
- T: Stream<Item = Result<O, Error>> + Unpin,
+ T: Stream<Item = Result<O, E>> + Unpin,
O: Into<Bytes>,
+ E: Into<Error>,
{
type Item = Result<Bytes, Error>;
@@ -93,7 +95,10 @@ where
match this.state {
EncoderState::Reading => {
if let Some(res) = ready!(Pin::new(&mut this.inner).poll_next(cx)) {
- let buf = res?;
+ let buf = match res {
+ Ok(buf) => buf,
+ Err(err) => return Poll::Ready(Some(Err(err.into()))),
+ };
this.input_buffer = buf.into();
this.state = EncoderState::Writing;
} else {
--
2.30.2
next prev parent reply other threads:[~2022-05-31 11:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 11:17 [pve-devel] [PATCH proxmox/backup/common/storage/wt] add tar.zst download in pve Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-05-31 11:17 ` Dominik Csapak [this message]
2022-05-31 11:17 ` [pbs-devel] [PATCH proxmox 1/2] proxmox-compression: make ZstdEncoder stream a bit more generic Dominik Csapak
2022-07-05 11:47 ` [pve-devel] applied-both: " Wolfgang Bumiller
2022-07-05 11:47 ` [pbs-devel] " Wolfgang Bumiller
2022-05-31 11:17 ` [pve-devel] [PATCH proxmox 2/2] proxmox-compression: add 'tar_directory' Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-05-31 11:17 ` [pve-devel] [PATCH proxmox-backup 1/2] restore-daemon: add 'format' parameter to the 'extract' handler Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-07-05 11:39 ` [pve-devel] " Wolfgang Bumiller
2022-07-05 11:39 ` Wolfgang Bumiller
2022-05-31 11:17 ` [pve-devel] [PATCH proxmox-backup 2/2] file-restore: add 'tar' option to 'extract' command Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-07-05 11:43 ` [pve-devel] " Wolfgang Bumiller
2022-07-05 11:43 ` Wolfgang Bumiller
2022-05-31 11:17 ` [pve-devel] [PATCH common 1/1] PBSClient: add 'tar' parameter to file_restore_extract Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-05-31 11:17 ` [pve-devel] [PATCH storage 1/1] api/filerestore: add 'tar' parameter to 'download' api Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-05-31 11:17 ` [pve-devel] [PATCH widget-toolkit 1/1] window/FileBrowser: enable tar button by default Dominik Csapak
2022-05-31 11:17 ` [pbs-devel] " Dominik Csapak
2022-07-01 12:12 ` [pve-devel] [PATCH proxmox/backup/common/storage/wt] add tar.zst download in pve Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220531111726.2972022-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal