From 27ff98000b0cdf0ed30eb8837c7d44cd3e79d32f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 25 May 2023 17:52:08 +0300 Subject: feat(tvix/store): eliminate generics in BlobStore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To construct various stores at runtime, we need to eliminate associated types from the BlobService trait, and return Box instead of specific types. This also means we can't consume self in the close() method, so everything we write to is put in an Option<>, and during the first close we take from there. Change-Id: Ia523b6ab2f2a5276f51cb5d17e81a5925bce69b6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8647 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/store/src/nar/non_caching_calculation_service.rs | 13 +++++-------- tvix/store/src/nar/renderer.rs | 9 ++++----- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'tvix/store/src/nar') diff --git a/tvix/store/src/nar/non_caching_calculation_service.rs b/tvix/store/src/nar/non_caching_calculation_service.rs index 8a080cb4df..b743f264b0 100644 --- a/tvix/store/src/nar/non_caching_calculation_service.rs +++ b/tvix/store/src/nar/non_caching_calculation_service.rs @@ -10,22 +10,19 @@ use super::{NARCalculationService, RenderError}; /// A NAR calculation service which simply renders the whole NAR whenever /// we ask for the calculation. -#[derive(Clone)] -pub struct NonCachingNARCalculationService { - nar_renderer: NARRenderer, +pub struct NonCachingNARCalculationService { + nar_renderer: NARRenderer, } -impl NonCachingNARCalculationService { - pub fn new(blob_service: BS, directory_service: DS) -> Self { +impl NonCachingNARCalculationService { + pub fn new(blob_service: Box, directory_service: DS) -> Self { Self { nar_renderer: NARRenderer::new(blob_service, directory_service), } } } -impl NARCalculationService - for NonCachingNARCalculationService -{ +impl NARCalculationService for NonCachingNARCalculationService { fn calculate_nar(&self, root_node: &proto::node::Node) -> Result<(u64, [u8; 32]), RenderError> { let h = Sha256::new(); let mut cw = CountWrite::from(h); diff --git a/tvix/store/src/nar/renderer.rs b/tvix/store/src/nar/renderer.rs index c10f2ddf52..a9a6d989e1 100644 --- a/tvix/store/src/nar/renderer.rs +++ b/tvix/store/src/nar/renderer.rs @@ -11,14 +11,13 @@ use tracing::warn; /// A NAR renderer, using a blob_service, chunk_service and directory_service /// to render a NAR to a writer. -#[derive(Clone)] -pub struct NARRenderer { - blob_service: BS, +pub struct NARRenderer { + blob_service: Box, directory_service: DS, } -impl NARRenderer { - pub fn new(blob_service: BS, directory_service: DS) -> Self { +impl NARRenderer { + pub fn new(blob_service: Box, directory_service: DS) -> Self { Self { blob_service, directory_service, -- cgit 1.4.1