diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-31T14·13+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-12-31T22·18+0000 |
commit | 9ca1353122e6c1c5cf88d2ed5839fe385be1d5d0 (patch) | |
tree | 010bc4ec556a7e9e109cc0f74051363187d68f76 /tvix/castore/src | |
parent | e2b6c77bfc4d00ba275d8029fe333d6064c268e9 (diff) |
refactor(tvix/castore/blobsvc): return Box, not Arc r/7293
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: I7bd337cd2e4c2d4154b385461eefa62c9b78345d Reviewed-on: https://cl.tvl.fyi/c/depot/+/10482 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/blobservice/from_addr.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/tvix/castore/src/blobservice/from_addr.rs b/tvix/castore/src/blobservice/from_addr.rs index 8f8e59952662..db221f05ab3b 100644 --- a/tvix/castore/src/blobservice/from_addr.rs +++ b/tvix/castore/src/blobservice/from_addr.rs @@ -1,4 +1,3 @@ -use std::sync::Arc; use url::Url; use crate::{proto::blob_service_client::BlobServiceClient, Error}; @@ -16,7 +15,7 @@ use super::{ /// - `simplefs://` ([SimpleFilesystemBlobService]) /// /// See their `from_url` methods for more details about their syntax. -pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error> { +pub async fn from_addr(uri: &str) -> Result<Box<dyn BlobService>, crate::Error> { let url = Url::parse(uri) .map_err(|e| crate::Error::StorageError(format!("unable to parse url: {}", e)))?; @@ -25,7 +24,7 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error> if url.has_host() || !url.path().is_empty() { return Err(Error::StorageError("invalid url".to_string())); } - Arc::new(MemoryBlobService::default()) + Box::<MemoryBlobService>::default() } else if url.scheme() == "sled" { // sled doesn't support host, and a path can be provided (otherwise // it'll live in memory only). @@ -42,11 +41,11 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error> // TODO: expose other parameters as URL parameters? if url.path().is_empty() { - return Ok(Arc::new( + return Ok(Box::new( SledBlobService::new_temporary().map_err(|e| Error::StorageError(e.to_string()))?, )); } - return Ok(Arc::new( + return Ok(Box::new( SledBlobService::new(url.path()).map_err(|e| Error::StorageError(e.to_string()))?, )); } else if url.scheme().starts_with("grpc+") { @@ -56,13 +55,13 @@ pub async fn from_addr(uri: &str) -> Result<Arc<dyn BlobService>, crate::Error> // - 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 = BlobServiceClient::new(crate::tonic::channel_from_url(&url).await?); - Arc::new(GRPCBlobService::from_client(client)) + Box::new(GRPCBlobService::from_client(client)) } else if url.scheme() == "simplefs" { if url.path().is_empty() { return Err(Error::StorageError("Invalid filesystem path".to_string())); } - Arc::new(SimpleFilesystemBlobService::new(url.path().into()).await?) + Box::new(SimpleFilesystemBlobService::new(url.path().into()).await?) } else { Err(crate::Error::StorageError(format!( "unknown scheme: {}", |