@@ -512,9 +512,9 @@ impl ImportSource {
512512}
513513
514514/// Use BaoFileHandle as the entry type for the map.
515- pub type Entry = BaoFileHandle ;
515+ pub type Entry < T > = BaoFileHandle < T > ;
516516
517- impl super :: MapEntry for Entry {
517+ impl < T > super :: MapEntry for Entry < T > {
518518 fn hash ( & self ) -> Hash {
519519 self . hash ( )
520520 }
@@ -530,15 +530,15 @@ impl super::MapEntry for Entry {
530530 }
531531
532532 async fn outboard ( & self ) -> io:: Result < impl Outboard > {
533- self . outboard ( )
533+ BaoFileHandle :: outboard ( self )
534534 }
535535
536536 async fn data_reader ( & self ) -> io:: Result < impl AsyncSliceReader > {
537537 Ok ( self . data_reader ( ) )
538538 }
539539}
540540
541- impl super :: MapEntryMut for Entry {
541+ impl < T > super :: MapEntryMut for Entry < T > {
542542 async fn batch_writer ( & self ) -> io:: Result < impl BaoBatchWriter > {
543543 Ok ( self . writer ( ) )
544544 }
@@ -572,12 +572,12 @@ pub(crate) struct Export {
572572}
573573
574574#[ derive( derive_more:: Debug ) ]
575- pub ( crate ) enum ActorMessage {
575+ pub ( crate ) enum ActorMessage < T > {
576576 // Query method: get a file handle for a hash, if it exists.
577577 // This will produce a file handle even for entries that are not yet in redb at all.
578578 Get {
579579 hash : Hash ,
580- tx : oneshot:: Sender < ActorResult < Option < BaoFileHandle > > > ,
580+ tx : oneshot:: Sender < ActorResult < Option < BaoFileHandle < T > > > > ,
581581 } ,
582582 /// Query method: get the rough entry status for a hash. Just complete, partial or not found.
583583 EntryStatus {
@@ -609,15 +609,15 @@ pub(crate) enum ActorMessage {
609609 /// will be created, but not yet written to redb.
610610 GetOrCreate {
611611 hash : Hash ,
612- tx : oneshot:: Sender < ActorResult < BaoFileHandle > > ,
612+ tx : oneshot:: Sender < ActorResult < BaoFileHandle < T > > > ,
613613 } ,
614614 /// Modification method: inline size was exceeded for a partial entry.
615615 /// If the entry is complete, this is a no-op. If the entry is partial and in
616616 /// memory, it will be written to a file and created in redb.
617617 OnMemSizeExceeded { hash : Hash } ,
618618 /// Modification method: marks a partial entry as complete.
619619 /// Calling this on a complete entry is a no-op.
620- OnComplete { handle : BaoFileHandle } ,
620+ OnComplete { handle : BaoFileHandle < T > } ,
621621 /// Modification method: import data into a redb store
622622 ///
623623 /// At this point the size, hash and outboard must already be known.
@@ -718,7 +718,7 @@ pub(crate) enum ActorMessage {
718718 Shutdown { tx : Option < oneshot:: Sender < ( ) > > } ,
719719}
720720
721- impl ActorMessage {
721+ impl < T > ActorMessage < T > {
722722 fn category ( & self ) -> MessageCategory {
723723 match self {
724724 Self :: Get { .. }
@@ -810,8 +810,8 @@ impl Store {
810810}
811811
812812#[ derive( Debug ) ]
813- struct StoreInner < T > {
814- tx : async_channel:: Sender < ActorMessage > ,
813+ struct StoreInner < T : Persistence > {
814+ tx : async_channel:: Sender < ActorMessage < T :: File > > ,
815815 temp : Arc < RwLock < TempCounterMap > > ,
816816 handle : Option < std:: thread:: JoinHandle < ( ) > > ,
817817 path_options : Arc < PathOptions > ,
@@ -1019,7 +1019,7 @@ where
10191019 Ok ( rx. recv ( ) ??)
10201020 }
10211021
1022- async fn complete ( & self , entry : Entry ) -> OuterResult < ( ) > {
1022+ async fn complete ( & self , entry : Entry < T :: File > ) -> OuterResult < ( ) > {
10231023 self . tx
10241024 . send ( ActorMessage :: OnComplete { handle : entry } )
10251025 . await ?;
@@ -1245,11 +1245,11 @@ impl<T> Drop for StoreInner<T> {
12451245 }
12461246}
12471247
1248- struct ActorState < T > {
1249- handles : BTreeMap < Hash , BaoFileHandleWeak > ,
1248+ struct ActorState < T : Persistence > {
1249+ handles : BTreeMap < Hash , BaoFileHandleWeak < T :: File > > ,
12501250 protected : BTreeSet < Hash > ,
12511251 temp : Arc < RwLock < TempCounterMap > > ,
1252- msgs_rx : async_channel:: Receiver < ActorMessage > ,
1252+ msgs_rx : async_channel:: Receiver < ActorMessage < T :: File > > ,
12531253 create_options : Arc < BaoFileConfig > ,
12541254 options : Options ,
12551255 rt : tokio:: runtime:: Handle ,
@@ -1320,8 +1320,8 @@ pub(crate) enum OuterError {
13201320 JoinTask ( #[ from] tokio:: task:: JoinError ) ,
13211321}
13221322
1323- impl From < async_channel:: SendError < ActorMessage > > for OuterError {
1324- fn from ( _e : async_channel:: SendError < ActorMessage > ) -> Self {
1323+ impl < T > From < async_channel:: SendError < ActorMessage < T > > > for OuterError {
1324+ fn from ( _e : async_channel:: SendError < ActorMessage < T > > ) -> Self {
13251325 OuterError :: Send
13261326 }
13271327}
@@ -1613,14 +1613,17 @@ pub(super) async fn gc_sweep_task(
16131613 Ok ( ( ) )
16141614}
16151615
1616- impl < T > Actor < T > {
1616+ impl < T > Actor < T >
1617+ where
1618+ T : Persistence ,
1619+ {
16171620 fn new_with_backend (
16181621 path : & Path ,
16191622 options : Options ,
16201623 temp : Arc < RwLock < TempCounterMap > > ,
16211624 rt : tokio:: runtime:: Handle ,
16221625 fs : T ,
1623- ) -> ActorResult < ( Self , async_channel:: Sender < ActorMessage > ) > {
1626+ ) -> ActorResult < ( Self , async_channel:: Sender < ActorMessage < T :: File > > ) > {
16241627 let db = match redb:: Database :: create ( path) {
16251628 Ok ( db) => db,
16261629 Err ( DatabaseError :: UpgradeRequired ( 1 ) ) => {
@@ -1787,7 +1790,7 @@ where
17871790 & mut self ,
17881791 tables : & impl ReadableTables ,
17891792 hash : Hash ,
1790- ) -> ActorResult < Option < BaoFileHandle > > {
1793+ ) -> ActorResult < Option < BaoFileHandle < T :: File > > > {
17911794 if let Some ( handle) = self . handles . get ( & hash) . and_then ( |weak| weak. upgrade ( ) ) {
17921795 return Ok ( Some ( handle) ) ;
17931796 }
@@ -2033,7 +2036,7 @@ where
20332036 & mut self ,
20342037 tables : & impl ReadableTables ,
20352038 hash : Hash ,
2036- ) -> ActorResult < BaoFileHandle > {
2039+ ) -> ActorResult < BaoFileHandle < T :: File > > {
20372040 self . protected . insert ( hash) ;
20382041 if let Some ( handle) = self . handles . get ( & hash) . and_then ( |x| x. upgrade ( ) ) {
20392042 return Ok ( handle) ;
@@ -2344,7 +2347,11 @@ where
23442347 Ok ( ( ) )
23452348 }
23462349
2347- fn on_complete ( & mut self , tables : & mut Tables , entry : BaoFileHandle ) -> ActorResult < ( ) > {
2350+ fn on_complete (
2351+ & mut self ,
2352+ tables : & mut Tables ,
2353+ entry : BaoFileHandle < T :: File > ,
2354+ ) -> ActorResult < ( ) > {
23482355 let hash = entry. hash ( ) ;
23492356 let mut info = None ;
23502357 tracing:: trace!( "on_complete({})" , hash. to_hex( ) ) ;
@@ -2414,7 +2421,11 @@ where
24142421 Ok ( ( ) )
24152422 }
24162423
2417- fn handle_toplevel ( & mut self , db : & redb:: Database , msg : ActorMessage ) -> ActorResult < ( ) > {
2424+ fn handle_toplevel (
2425+ & mut self ,
2426+ db : & redb:: Database ,
2427+ msg : ActorMessage < T :: File > ,
2428+ ) -> ActorResult < ( ) > {
24182429 match msg {
24192430 ActorMessage :: UpdateInlineOptions {
24202431 inline_options,
@@ -2448,8 +2459,8 @@ where
24482459 fn handle_readonly (
24492460 & mut self ,
24502461 tables : & impl ReadableTables ,
2451- msg : ActorMessage ,
2452- ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage > > {
2462+ msg : ActorMessage < T :: File > ,
2463+ ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage < T :: File > > > {
24532464 match msg {
24542465 ActorMessage :: Get { hash, tx } => {
24552466 let res = self . get ( tables, hash) ;
@@ -2495,8 +2506,8 @@ where
24952506 fn handle_readwrite (
24962507 & mut self ,
24972508 tables : & mut Tables ,
2498- msg : ActorMessage ,
2499- ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage > > {
2509+ msg : ActorMessage < T :: File > ,
2510+ ) -> ActorResult < std:: result:: Result < ( ) , ActorMessage < T :: File > > > {
25002511 match msg {
25012512 ActorMessage :: Import { cmd, tx } => {
25022513 let res = self . import ( tables, cmd) ;
0 commit comments