[pbs-devel] [RFC proxmox-backup 07/24] server: sync: move reader trait to common sync module

Gabriel Goller g.goller at proxmox.com
Tue Jul 30 10:38:16 CEST 2024


On 23.07.2024 09:32, Christian Ebner wrote:
>On 7/16/24 11:53, Gabriel Goller wrote:
>>On 15.07.2024 12:15, Christian Ebner wrote:
>>>pub(crate) struct PullTarget {
>>>    store: Arc<DataStore>,
>>>    ns: BackupNamespace,
>>>@@ -97,7 +85,7 @@ trait PullSource: Send + Sync {
>>>        &self,
>>>        ns: &BackupNamespace,
>>>        dir: &BackupDir,
>>>-    ) -> Result<Arc<dyn PullReader>, Error>;
>>>+    ) -> Result<Arc<dyn SyncSourceReader>, Error>;
>>>}
>>>
>>>#[async_trait::async_trait]
>>
>>AFAIK we are currently on rust 1.79.0, which has async fn's in traits
>>already stabilized. This means we can remove the async_trait create.
>>https://releases.rs/docs/1.75.0/
>
>Thanks for pointing this out!
>
>However, dropping the `async_trait` macro does not work out, as these 
>traits are used as base for trait objects, which therefore require the 
>trait to be object safe, see 
>https://doc.rust-lang.org/reference/items/traits.html#object-safety
>
>So the Rust compiler complains with, e.g.
>
>```
>error[E0038]: the trait `SyncSource` cannot be made into an object
>```
>
>Therefore I would opt to keep this as is, unless I'm overlooking 
>something here.

Oops, yeah missed that. This was even mentioned in the initial async fn
blog post:
https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#dynamic-dispatch.

We could make PullParameters generic and change source to accept a `impl
PullSource`, but I agree, let's keep this as it is for now :).




More information about the pbs-devel mailing list