99//
1010// SPDX-License-Identifier: Apache-2.0
1111
12- //std dependencies
12+ use std :: cell :: RefCell ;
1313use std:: collections:: HashMap ;
1414use std:: fs;
1515use std:: path:: PathBuf ;
@@ -42,7 +42,7 @@ pub struct GenericKvs<J: KvsBackend> {
4242 filename_prefix : PathBuf ,
4343
4444 /// Flush on exit flag
45- flush_on_exit : FlushOnExit ,
45+ flush_on_exit : RefCell < FlushOnExit > ,
4646
4747 _backend : std:: marker:: PhantomData < J > ,
4848}
@@ -236,7 +236,7 @@ impl<J: KvsBackend> KvsApi for GenericKvs<J> {
236236 kvs : Mutex :: new ( kvs) ,
237237 default,
238238 filename_prefix,
239- flush_on_exit : FlushOnExit :: Yes ,
239+ flush_on_exit : RefCell :: new ( FlushOnExit :: Yes ) ,
240240 _backend : std:: marker:: PhantomData ,
241241 } )
242242 }
@@ -246,15 +246,15 @@ impl<J: KvsBackend> KvsApi for GenericKvs<J> {
246246 /// # Return Values
247247 /// * `FlushOnExit`: Current flush on exit behavior.
248248 fn flush_on_exit ( & self ) -> FlushOnExit {
249- self . flush_on_exit . clone ( )
249+ self . flush_on_exit . borrow ( ) . clone ( )
250250 }
251251
252252 /// Control the flush on exit behavior
253253 ///
254254 /// # Parameters
255255 /// * `flush_on_exit`: Flag to control flush-on-exit behavior
256- fn set_flush_on_exit ( & mut self , flush_on_exit : FlushOnExit ) {
257- self . flush_on_exit = flush_on_exit;
256+ fn set_flush_on_exit ( & self , flush_on_exit : FlushOnExit ) {
257+ * self . flush_on_exit . borrow_mut ( ) = flush_on_exit
258258 }
259259
260260 /// Resets a key-value-storage to its initial state
@@ -1025,7 +1025,7 @@ mod kvs_tests {
10251025
10261026 #[ test]
10271027 fn test_set_flush_on_exit ( ) {
1028- let mut kvs = get_kvs :: < MockBackend > ( PathBuf :: new ( ) , KvsMap :: new ( ) , KvsMap :: new ( ) ) ;
1028+ let kvs = get_kvs :: < MockBackend > ( PathBuf :: new ( ) , KvsMap :: new ( ) , KvsMap :: new ( ) ) ;
10291029
10301030 kvs. set_flush_on_exit ( FlushOnExit :: Yes ) ;
10311031 assert_eq ! ( kvs. flush_on_exit( ) , FlushOnExit :: Yes ) ;
@@ -1201,7 +1201,7 @@ mod kvs_tests {
12011201 let dir = tempdir ( ) . unwrap ( ) ;
12021202 let dir_path = dir. path ( ) . to_path_buf ( ) ;
12031203 {
1204- let mut kvs = get_kvs :: < JsonBackend > ( dir_path. clone ( ) , KvsMap :: new ( ) , KvsMap :: new ( ) ) ;
1204+ let kvs = get_kvs :: < JsonBackend > ( dir_path. clone ( ) , KvsMap :: new ( ) , KvsMap :: new ( ) ) ;
12051205 kvs. set_flush_on_exit ( FlushOnExit :: Yes ) ;
12061206 kvs. set_value ( "key" , "value" ) . unwrap ( ) ;
12071207 }
0 commit comments