[pbs-devel] [PATCH pxar 1/2] make aio::Encoder actually behave with async
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Feb 9 15:20:08 CET 2021
I'll have an in-depth look another time, just a quick noteinline:
On Tue, Feb 09, 2021 at 01:03:47PM +0100, Stefan Reiter wrote:
> To really use the encoder with async/await, it needs to support
> SeqWrite implementations that are Send. This requires changing a whole
> bunch of '&mut dyn SeqWrite' trait objects to instead take a 'T:
> SeqWrite' generic parameter directly instead. Most of this is quite
> straightforward, though incurs a lot of churn (FileImpl needs a generic
> parameter now for example).
>
> The trickiest part is returning a new Encoder instance in
> create_directory, as the trait object trick with
> SeqWrite::as_trait_object doesn't work if SeqWrite is implemented for
> generic '&mut S'.
>
> Instead, work with the generic object directly, and express the
> owned/borrowed state in the Encoder (to avoid nested borrowing) as an
> enum EncoderOutput.
>
> Add to the aio test to ensure the Encoder is now actually useable.
>
> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
> ---
> src/encoder/aio.rs | 48 ++++++++---------
> src/encoder/mod.rs | 128 +++++++++++++++++++++++---------------------
> src/encoder/sync.rs | 28 ++++------
> 3 files changed, 101 insertions(+), 103 deletions(-)
>
> diff --git a/src/encoder/aio.rs b/src/encoder/aio.rs
> index f4b96b3..6b90ce5 100644
> --- a/src/encoder/aio.rs
> +++ b/src/encoder/aio.rs
> @@ -13,12 +13,12 @@ use crate::Metadata;
> ///
> /// This is the `async` version of the `pxar` encoder.
> #[repr(transparent)]
> -pub struct Encoder<'a, T: SeqWrite + 'a> {
> +pub struct Encoder<'a, T: SeqWrite + 'a + Send> {
^ This requirement should not strictly be necessary for Encoder to
become Send. Send will propagate anyway. (You would only need this if
you wanted to pass it as an `&dyn SeqWrite + Send` later on.
Plus, I do not want to force this to be part of the API. It's very much
possible to want to be able to reference non-Send local data in a
single-threaded executor.
More information about the pbs-devel
mailing list