about summary refs log tree commit diff
path: root/tvix/store/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-01-09T09·04+0200
committerclbot <clbot@tvl.fyi>2024-01-09T14·08+0000
commit89882ff9b13ff1c25fc64605e3fc87ae7b9ab877 (patch)
tree4eaf9a8d3214ec8acda1fa5f94c2fc9624438518 /tvix/store/src
parent8fbdf72825843416dc1923d91cb20059cdbc07b1 (diff)
refactor(tvix): use AsRef<dyn …> instead of Deref<Target= …> r/7359
Removes some more needs for Arcs.

Change-Id: I9a9f4b81641c271de260e9ffa98313a32944d760
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10578
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/store/src')
-rw-r--r--tvix/store/src/pathinfoservice/fs/mod.rs13
-rw-r--r--tvix/store/src/utils.rs19
2 files changed, 15 insertions, 17 deletions
diff --git a/tvix/store/src/pathinfoservice/fs/mod.rs b/tvix/store/src/pathinfoservice/fs/mod.rs
index df7a42e91f59..b7657d638402 100644
--- a/tvix/store/src/pathinfoservice/fs/mod.rs
+++ b/tvix/store/src/pathinfoservice/fs/mod.rs
@@ -1,6 +1,5 @@
 use futures::Stream;
 use futures::StreamExt;
-use std::ops::Deref;
 use std::pin::Pin;
 use tonic::async_trait;
 use tvix_castore::fs::{RootNodes, TvixStoreFs};
@@ -21,9 +20,9 @@ pub fn make_fs<BS, DS, PS>(
     list_root: bool,
 ) -> TvixStoreFs<BS, DS, RootNodesWrapper<PS>>
 where
-    BS: Deref<Target = dyn BlobService> + Send + Clone + 'static,
-    DS: Deref<Target = dyn DirectoryService> + Send + Clone + 'static,
-    PS: Deref<Target = dyn PathInfoService> + Send + Sync + Clone + 'static,
+    BS: AsRef<dyn BlobService> + Send + Clone + 'static,
+    DS: AsRef<dyn DirectoryService> + Send + Clone + 'static,
+    PS: AsRef<dyn PathInfoService> + Send + Sync + Clone + 'static,
 {
     TvixStoreFs::new(
         blob_service,
@@ -46,7 +45,7 @@ pub struct RootNodesWrapper<T>(pub(crate) T);
 #[async_trait]
 impl<T> RootNodes for RootNodesWrapper<T>
 where
-    T: Deref<Target = dyn PathInfoService> + Send + Sync,
+    T: AsRef<dyn PathInfoService> + Send + Sync,
 {
     async fn get_by_basename(&self, name: &[u8]) -> Result<Option<castorepb::node::Node>, Error> {
         let Ok(store_path) = nix_compat::store_path::StorePath::from_bytes(name) else {
@@ -55,7 +54,7 @@ where
 
         Ok(self
             .0
-            .deref()
+            .as_ref()
             .get(*store_path.digest())
             .await?
             .map(|path_info| {
@@ -68,7 +67,7 @@ where
     }
 
     fn list(&self) -> Pin<Box<dyn Stream<Item = Result<castorepb::node::Node, Error>> + Send>> {
-        Box::pin(self.0.deref().list().map(|result| {
+        Box::pin(self.0.as_ref().list().map(|result| {
             result.map(|path_info| {
                 path_info
                     .node
diff --git a/tvix/store/src/utils.rs b/tvix/store/src/utils.rs
index 6edbf94eec33..e7e4b7c79fad 100644
--- a/tvix/store/src/utils.rs
+++ b/tvix/store/src/utils.rs
@@ -1,4 +1,4 @@
-use std::{ops::Deref, path::Path, sync::Arc};
+use std::{path::Path, sync::Arc};
 
 use data_encoding::BASE64;
 use nix_compat::store_path::{self, StorePath};
@@ -53,9 +53,9 @@ pub async fn import_path<BS, DS, PS, P>(
 ) -> Result<StorePath, std::io::Error>
 where
     P: AsRef<Path> + std::fmt::Debug,
-    BS: Deref<Target = dyn BlobService> + Clone,
-    DS: Deref<Target = dyn DirectoryService>,
-    PS: Deref<Target = dyn PathInfoService>,
+    BS: AsRef<dyn BlobService> + Clone,
+    DS: AsRef<dyn DirectoryService>,
+    PS: AsRef<dyn PathInfoService>,
 {
     // calculate the name
     // TODO: make a path_to_name helper function?
@@ -71,15 +71,14 @@ where
         })?;
 
     // Ingest the path into blob and directory service.
-    let root_node =
-        tvix_castore::import::ingest_path(blob_service, &directory_service.deref(), &path)
-            .await
-            .expect("failed to ingest path");
+    let root_node = tvix_castore::import::ingest_path(blob_service, &directory_service, &path)
+        .await
+        .expect("failed to ingest path");
 
     debug!(root_node =?root_node, "import successful");
 
     // Ask the PathInfoService for the NAR size and sha256
-    let (nar_size, nar_sha256) = path_info_service.calculate_nar(&root_node).await?;
+    let (nar_size, nar_sha256) = path_info_service.as_ref().calculate_nar(&root_node).await?;
 
     // Calculate the output path. This might still fail, as some names are illegal.
     let output_path = store_path::build_nar_based_store_path(&nar_sha256, name).map_err(|_| {
@@ -115,7 +114,7 @@ where
 
     // put into [PathInfoService], and return the PathInfo that we get back
     // from there (it might contain additional signatures).
-    let _path_info = path_info_service.put(path_info).await?;
+    let _path_info = path_info_service.as_ref().put(path_info).await?;
 
     Ok(output_path.to_owned())
 }