]> git.proxmox.com Git - pxar.git/commit
make aio::Encoder actually behave with async
authorStefan Reiter <s.reiter@proxmox.com>
Tue, 9 Feb 2021 12:03:47 +0000 (13:03 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 17 Feb 2021 08:20:40 +0000 (09:20 +0100)
commitd84024338a4987107a0f0d2f92edc686fd8709f9
tree72b7467368062f95b6f1dcd5078ea4d1ab71bbc7
parent8bff2f7c7edfe7f71232879b9f96bff6ca2c629f
make aio::Encoder actually behave with async

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@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/encoder/aio.rs
src/encoder/mod.rs
src/encoder/sync.rs