From f4a7b325e9d44fc2fd002e7cf2eb9361528017a9 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 22 May 2023 19:40:13 +0300 Subject: feat(tvix/store/blobsvc): add constructors Change-Id: I55e06bf4e8a11dc2caf92c597558f1b820b42566 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8610 Reviewed-by: tazjin Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/store/src/blobservice/grpc.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tvix/store') diff --git a/tvix/store/src/blobservice/grpc.rs b/tvix/store/src/blobservice/grpc.rs index 9c07345839e3..0b08fbf46ad9 100644 --- a/tvix/store/src/blobservice/grpc.rs +++ b/tvix/store/src/blobservice/grpc.rs @@ -22,7 +22,29 @@ pub struct GRPCBlobService { grpc_client: proto::blob_service_client::BlobServiceClient, } -// TODO: provide some contstructors +impl GRPCBlobService { + /// construct a [GRPCBlobService] from a [proto::blob_service_client::BlobServiceClient], + /// and a [tokio::runtime::Handle]. + pub fn new( + grpc_client: proto::blob_service_client::BlobServiceClient, + tokio_handle: tokio::runtime::Handle, + ) -> Self { + Self { + tokio_handle, + grpc_client, + } + } + /// construct a [GRPCBlobService] from a [proto::blob_service_client::BlobServiceClient]. + /// panics if called outside the context of a tokio runtime. + pub fn from_client( + grpc_client: proto::blob_service_client::BlobServiceClient, + ) -> Self { + Self { + tokio_handle: tokio::runtime::Handle::current(), + grpc_client, + } + } +} impl BlobService for GRPCBlobService { type BlobReader = Box; -- cgit 1.4.1