From 41935fab702f534ce7b787ef5f6e9f2ac2e7ce00 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 31 Dec 2023 16:26:02 +0200 Subject: refactor(tvix/castore/directorysvc): return Box, not Arc While we currently mostly use it in an Arc, as we need to clone it inside PathInfoService, there might be other usecases not requiring it to be Clone. Change-Id: Ia05bb370340792a048e2036be30e285ef1e63870 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10483 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/castore/src/directoryservice/from_addr.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tvix/castore') diff --git a/tvix/castore/src/directoryservice/from_addr.rs b/tvix/castore/src/directoryservice/from_addr.rs index bd1bf584cf29..0a5a0464c14a 100644 --- a/tvix/castore/src/directoryservice/from_addr.rs +++ b/tvix/castore/src/directoryservice/from_addr.rs @@ -1,4 +1,3 @@ -use std::sync::Arc; use url::Url; use crate::{proto::directory_service_client::DirectoryServiceClient, Error}; @@ -19,7 +18,7 @@ use super::{DirectoryService, GRPCDirectoryService, MemoryDirectoryService, Sled /// Connects to a local tvix-store gRPC service via Unix socket. /// - `grpc+http://host:port`, `grpc+https://host:port` /// Connects to a (remote) tvix-store gRPC service. -pub async fn from_addr(uri: &str) -> Result, crate::Error> { +pub async fn from_addr(uri: &str) -> Result, crate::Error> { let url = Url::parse(uri) .map_err(|e| crate::Error::StorageError(format!("unable to parse url: {}", e)))?; @@ -28,7 +27,7 @@ pub async fn from_addr(uri: &str) -> Result, crate::Er if url.has_host() || !url.path().is_empty() { return Err(Error::StorageError("invalid url".to_string())); } - Arc::new(MemoryDirectoryService::default()) + Box::::default() } else if url.scheme() == "sled" { // sled doesn't support host, and a path can be provided (otherwise // it'll live in memory only). @@ -45,12 +44,12 @@ pub async fn from_addr(uri: &str) -> Result, crate::Er // TODO: expose compression and other parameters as URL parameters? if url.path().is_empty() { - return Ok(Arc::new( + return Ok(Box::new( SledDirectoryService::new_temporary() .map_err(|e| Error::StorageError(e.to_string()))?, )); } - return Ok(Arc::new( + return Ok(Box::new( SledDirectoryService::new(url.path()) .map_err(|e| Error::StorageError(e.to_string()))?, )); @@ -61,7 +60,7 @@ pub async fn from_addr(uri: &str) -> Result, crate::Er // - In the case of non-unix sockets, there must be a host, but no path. // Constructing the channel is handled by tvix_castore::channel::from_url. let client = DirectoryServiceClient::new(crate::tonic::channel_from_url(&url).await?); - Arc::new(GRPCDirectoryService::from_client(client)) + Box::new(GRPCDirectoryService::from_client(client)) } else { Err(crate::Error::StorageError(format!( "unknown scheme: {}", -- cgit 1.4.1