From 6f5474bf028045cc3cb64eff04cf80aef7e22412 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 23 Mar 2024 21:10:05 +0100 Subject: feat(tvix/castore): AsRef impl DirectoryService 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 Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/castore/src/directoryservice/mod.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tvix/castore/src/directoryservice/mod.rs b/tvix/castore/src/directoryservice/mod.rs index f9d8e08b31..523c61d056 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; } +#[async_trait] +impl DirectoryService for A +where + A: AsRef + Send + Sync, +{ + async fn get(&self, digest: &B3Digest) -> Result, Error> { + self.as_ref().get(digest).await + } + + async fn put(&self, directory: proto::Directory) -> Result { + self.as_ref().put(directory).await + } + + fn get_recursive( + &self, + root_directory_digest: &B3Digest, + ) -> BoxStream> { + self.as_ref().get_recursive(root_directory_digest) + } + + fn put_multiple_start(&self) -> Box { + 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 -- cgit 1.4.1