about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-03-23T20·10+0100
committerclbot <clbot@tvl.fyi>2024-03-24T20·00+0000
commit6f5474bf028045cc3cb64eff04cf80aef7e22412 (patch)
tree2940c0860af3adc8c40c3a6193422e31f86d6970
parent21fcc1c9df2562a6cf39b2a0bf9e1e97fb14f711 (diff)
feat(tvix/castore): AsRef<dyn DirectoryService> impl DirectoryService r/7776
This allows us to use containers around DirectoryServices as DirectoryServices too.

Change-Id: I56cca27b3212858db8b12b874df0e567dd868711
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11248
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
-rw-r--r--tvix/castore/src/directoryservice/mod.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tvix/castore/src/directoryservice/mod.rs b/tvix/castore/src/directoryservice/mod.rs
index f9d8e08b31e0..523c61d056cc 100644
--- a/tvix/castore/src/directoryservice/mod.rs
+++ b/tvix/castore/src/directoryservice/mod.rs
@@ -63,6 +63,31 @@ pub trait DirectoryService: Send + Sync {
     fn put_multiple_start(&self) -> Box<dyn DirectoryPutter>;
 }
 
+#[async_trait]
+impl<A> DirectoryService for A
+where
+    A: AsRef<dyn DirectoryService> + Send + Sync,
+{
+    async fn get(&self, digest: &B3Digest) -> Result<Option<proto::Directory>, Error> {
+        self.as_ref().get(digest).await
+    }
+
+    async fn put(&self, directory: proto::Directory) -> Result<B3Digest, Error> {
+        self.as_ref().put(directory).await
+    }
+
+    fn get_recursive(
+        &self,
+        root_directory_digest: &B3Digest,
+    ) -> BoxStream<Result<proto::Directory, Error>> {
+        self.as_ref().get_recursive(root_directory_digest)
+    }
+
+    fn put_multiple_start(&self) -> Box<dyn DirectoryPutter> {
+        self.as_ref().put_multiple_start()
+    }
+}
+
 /// Provides a handle to put a closure of connected [proto::Directory] elements.
 ///
 /// The consumer can periodically call [DirectoryPutter::put], starting from the