From 89882ff9b13ff1c25fc64605e3fc87ae7b9ab877 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 9 Jan 2024 11:04:29 +0200 Subject: refactor(tvix): use AsRef instead of Deref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes some more needs for Arcs. Change-Id: I9a9f4b81641c271de260e9ffa98313a32944d760 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10578 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/castore/src/fs/mod.rs | 13 ++++++------- tvix/castore/src/fs/root_nodes.rs | 10 ++++++---- tvix/castore/src/fs/tests.rs | 5 ++--- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tvix/castore/src/fs') diff --git a/tvix/castore/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs index 2da072329d..632dad84cf 100644 --- a/tvix/castore/src/fs/mod.rs +++ b/tvix/castore/src/fs/mod.rs @@ -23,7 +23,6 @@ use fuse_backend_rs::abi::fuse_abi::stat64; use fuse_backend_rs::api::filesystem::{Context, FileSystem, FsOptions, ROOT_ID}; use futures::StreamExt; use parking_lot::RwLock; -use std::ops::Deref; use std::{ collections::HashMap, io, @@ -101,8 +100,8 @@ pub struct TvixStoreFs { impl TvixStoreFs where - BS: Deref + Clone + Send, - DS: Deref + Clone + Send + 'static, + BS: AsRef + Clone + Send, + DS: AsRef + Clone + Send + 'static, RN: RootNodes + Clone + 'static, { pub fn new( @@ -157,7 +156,7 @@ where .block_on(self.tokio_handle.spawn({ let directory_service = self.directory_service.clone(); let parent_digest = parent_digest.to_owned(); - async move { directory_service.get(&parent_digest).await } + async move { directory_service.as_ref().get(&parent_digest).await } })) .unwrap()? .ok_or_else(|| { @@ -270,8 +269,8 @@ where impl FileSystem for TvixStoreFs where - BS: Deref + Clone + Send + 'static, - DS: Deref + Send + Clone + 'static, + BS: AsRef + Clone + Send + 'static, + DS: AsRef + Send + Clone + 'static, RN: RootNodes + Clone + 'static, { type Handle = u64; @@ -496,7 +495,7 @@ where let task = self .tokio_handle - .spawn(async move { blob_service.open_read(&blob_digest).await }); + .spawn(async move { blob_service.as_ref().open_read(&blob_digest).await }); let blob_reader = self.tokio_handle.block_on(task).unwrap(); diff --git a/tvix/castore/src/fs/root_nodes.rs b/tvix/castore/src/fs/root_nodes.rs index 312a0b2cdd..a603fd1b37 100644 --- a/tvix/castore/src/fs/root_nodes.rs +++ b/tvix/castore/src/fs/root_nodes.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, ops::Deref, pin::Pin}; +use std::{collections::BTreeMap, pin::Pin}; use crate::{proto::node::Node, Error}; use bytes::Bytes; @@ -23,13 +23,15 @@ pub trait RootNodes: Send + Sync { /// the key is the node name. impl RootNodes for T where - T: Deref> + Send + Sync, + T: AsRef> + Send + Sync, { async fn get_by_basename(&self, name: &[u8]) -> Result, Error> { - Ok(self.get(name).cloned()) + Ok(self.as_ref().get(name).cloned()) } fn list(&self) -> Pin> + Send + '_>> { - Box::pin(tokio_stream::iter(self.iter().map(|(_, v)| Ok(v.clone())))) + Box::pin(tokio_stream::iter( + self.as_ref().iter().map(|(_, v)| Ok(v.clone())), + )) } } diff --git a/tvix/castore/src/fs/tests.rs b/tvix/castore/src/fs/tests.rs index 5f2916abd4..2f27c3c1c8 100644 --- a/tvix/castore/src/fs/tests.rs +++ b/tvix/castore/src/fs/tests.rs @@ -1,7 +1,6 @@ use std::{ collections::BTreeMap, io::{self, Cursor}, - ops::Deref, os::unix::fs::MetadataExt, path::Path, sync::Arc, @@ -43,8 +42,8 @@ fn do_mount, BS, DS>( list_root: bool, ) -> io::Result where - BS: Deref + Send + Sync + Clone + 'static, - DS: Deref + Send + Sync + Clone + 'static, + BS: AsRef + Send + Sync + Clone + 'static, + DS: AsRef + Send + Sync + Clone + 'static, { let fs = TvixStoreFs::new( blob_service, -- cgit 1.4.1