refactor(tvix): use AsRef<dyn …> instead of Deref<Target= …>

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>
This commit is contained in:
Florian Klink 2024-01-09 11:04:29 +02:00 committed by clbot
parent 8fbdf72825
commit 89882ff9b1
8 changed files with 58 additions and 69 deletions

View file

@ -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<BS, DS, RN> {
impl<BS, DS, RN> TvixStoreFs<BS, DS, RN>
where
BS: Deref<Target = dyn BlobService> + Clone + Send,
DS: Deref<Target = dyn DirectoryService> + Clone + Send + 'static,
BS: AsRef<dyn BlobService> + Clone + Send,
DS: AsRef<dyn DirectoryService> + 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<BS, DS, RN> FileSystem for TvixStoreFs<BS, DS, RN>
where
BS: Deref<Target = dyn BlobService> + Clone + Send + 'static,
DS: Deref<Target = dyn DirectoryService> + Send + Clone + 'static,
BS: AsRef<dyn BlobService> + Clone + Send + 'static,
DS: AsRef<dyn DirectoryService> + 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();

View file

@ -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<T> RootNodes for T
where
T: Deref<Target = BTreeMap<Bytes, Node>> + Send + Sync,
T: AsRef<BTreeMap<Bytes, Node>> + Send + Sync,
{
async fn get_by_basename(&self, name: &[u8]) -> Result<Option<Node>, Error> {
Ok(self.get(name).cloned())
Ok(self.as_ref().get(name).cloned())
}
fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + 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())),
))
}
}

View file

@ -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<P: AsRef<Path>, BS, DS>(
list_root: bool,
) -> io::Result<FuseDaemon>
where
BS: Deref<Target = dyn BlobService> + Send + Sync + Clone + 'static,
DS: Deref<Target = dyn DirectoryService> + Send + Sync + Clone + 'static,
BS: AsRef<dyn BlobService> + Send + Sync + Clone + 'static,
DS: AsRef<dyn DirectoryService> + Send + Sync + Clone + 'static,
{
let fs = TvixStoreFs::new(
blob_service,