Skip to content

Commit

Permalink
feat: impl is_async_incompatible for all backends
Browse files Browse the repository at this point in the history
  • Loading branch information
nardoor committed Nov 17, 2024
1 parent 6605f0c commit f1c3171
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/backend/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ impl ReadBackend for LocalBackend {

Ok(vec.into())
}

/// [`LocalBackend`] doesn't use `async`, even under the hood.
fn is_async_incompatible(&self) -> bool {
false
}
}

impl WriteBackend for LocalBackend {
Expand Down
9 changes: 9 additions & 0 deletions crates/backend/src/opendal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ impl ReadBackend for OpenDALBackend {
)?
.to_bytes())
}

/// [`OpenDALBackend`] is `sync` and uses `block_on(async Fn)` under the hood.
///
/// When implementing `rustic_core` using this backend in some `async` features will not work.
///
/// see https://github.com/rustic-rs/rustic/issues/1181
fn is_async_incompatible(&self) -> bool {
true
}
}

impl WriteBackend for OpenDALBackend {
Expand Down
4 changes: 4 additions & 0 deletions crates/backend/src/rclone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ impl ReadBackend for RcloneBackend {
) -> RusticResult<Bytes> {
self.rest.read_partial(tpe, id, cacheable, offset, length)
}
/// RcloneBackend uses `RestBackend`
fn is_async_incompatible(&self) -> bool {
self.rest.is_async_incompatible()
}
}

impl WriteBackend for RcloneBackend {
Expand Down
10 changes: 10 additions & 0 deletions crates/backend/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ impl ReadBackend for RestBackend {
)
.map_err(construct_backoff_error)
}

/// [`RestBackend`] uses `reqwest` which blocking implementation
/// uses an `async` runtime under the hood.
///
/// When implementing `rustic_core` using this backend in some `async` features will not work.
///
/// https://github.com/rustic-rs/rustic/issues/1181
fn is_async_incompatible(&self) -> bool {
true
}
}

fn construct_backoff_error(err: backoff::Error<reqwest::Error>) -> Box<RusticError> {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/backend/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ impl ReadBackend for CachedBackend {
fn warm_up(&self, tpe: FileType, id: &Id) -> RusticResult<()> {
self.be.warm_up(tpe, id)
}

fn is_async_incompatible(&self) -> bool {
self.be.is_async_incompatible()
}
}

impl WriteBackend for CachedBackend {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/backend/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ impl<C: CryptoKey> ReadBackend for DecryptBackend<C> {
) -> RusticResult<Bytes> {
self.be.read_partial(tpe, id, cacheable, offset, length)
}

fn is_async_incompatible(&self) -> bool {
self.be.is_async_incompatible()
}
}

impl<C: CryptoKey> WriteBackend for DecryptBackend<C> {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/backend/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ impl<BE: DecryptFullBackend> ReadBackend for DryRunBackend<BE> {
) -> RusticResult<Bytes> {
self.be.read_partial(tpe, id, cacheable, offset, length)
}

fn is_async_incompatible(&self) -> bool {
self.be.is_async_incompatible()
}
}

impl<BE: DecryptFullBackend> DecryptWriteBackend for DryRunBackend<BE> {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/backend/hotcold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ impl ReadBackend for HotColdBackend {
fn warm_up(&self, tpe: FileType, id: &Id) -> RusticResult<()> {
self.be.warm_up(tpe, id)
}

fn is_async_incompatible(&self) -> bool {
self.be.is_async_incompatible()
}
}

impl WriteBackend for HotColdBackend {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/backend/warm_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl ReadBackend for WarmUpAccessBackend {
_ = self.be.read_partial(tpe, id, false, 0, 1);
Ok(())
}

fn is_async_incompatible(&self) -> bool {
self.be.is_async_incompatible()
}
}

impl WriteBackend for WarmUpAccessBackend {
Expand Down
5 changes: 5 additions & 0 deletions crates/testing/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ pub mod in_memory_backend {
) -> RusticResult<Bytes> {
Ok(self.0.read().unwrap()[tpe][id].slice(offset as usize..(offset + length) as usize))
}

/// [`InMemoryBackend`] doesn't use `async`, even under the hood.
fn is_async_incompatible(&self) -> bool {
false
}
}

impl WriteBackend for InMemoryBackend {
Expand Down

0 comments on commit f1c3171

Please sign in to comment.