From 03f6c63373b57ee817b267a3b8f8eb7f61a378ce Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 26 Jun 2024 21:00:22 +0200 Subject: [PATCH] feat: impl Clone for Store (cherry picked from commit 90750c3c82ab0a5973de634661c5284c74fc89a8) --- rust/nix-store/src/store.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/rust/nix-store/src/store.rs b/rust/nix-store/src/store.rs index af820a1..d6cca3d 100644 --- a/rust/nix-store/src/store.rs +++ b/rust/nix-store/src/store.rs @@ -7,6 +7,7 @@ use nix_util::{check_call, result_string_init}; use std::ffi::{c_char, CString}; use std::ptr::null_mut; use std::ptr::NonNull; +use std::sync::Arc; /* TODO make Nix itself thread safe */ lazy_static! { @@ -33,7 +34,7 @@ impl Drop for StoreRef { } pub struct Store { - inner: StoreRef, + inner: Arc, /* An error context to reuse. This way we don't have to allocate them for each store operation. */ context: Context, } @@ -84,9 +85,9 @@ impl Store { panic!("nix_c_store_open returned a null pointer without an error"); } let store = Store { - inner: StoreRef { + inner: Arc::new(StoreRef { inner: NonNull::new(store).unwrap(), - }, + }), context, }; Ok(store) @@ -110,6 +111,15 @@ impl Store { } } +impl Clone for Store { + fn clone(&self) -> Self { + Store { + inner: self.inner.clone(), + context: Context::new(), + } + } +} + #[cfg(test)] mod tests { use std::collections::HashMap;