@@ -443,10 +443,14 @@ pub(crate) enum ImportSource {
443
443
444
444
/// trait which defines the backend persistence layer
445
445
/// for this store. e.g. filesystem, s3 etc
446
- pub trait Persistence : Clone {
446
+ pub trait Persistence {
447
447
/// the error type that is returned for the persistence layer
448
448
type Err ;
449
449
450
+ /// the type which represents a file which was read from the persistence
451
+ /// layer
452
+ type File ;
453
+
450
454
/// return the size of the file in bytes if it can be found/read
451
455
/// otherwise return a [Self::Err]
452
456
fn size ( & self , path : & Path ) -> impl Future < Output = Result < u64 , Self :: Err > > ;
@@ -458,6 +462,9 @@ pub trait Persistence: Clone {
458
462
459
463
/// recursively ensure that the input path exists
460
464
fn create_dir_all ( & self , path : & Path ) -> impl Future < Output = Result < ( ) , Self :: Err > > ;
465
+
466
+ /// read and return the file at the input path
467
+ fn open ( & self , path : & Path ) -> impl Future < Output = Result < Self :: File , Self :: Err > > ;
461
468
}
462
469
463
470
/// A persistence layer that writes to the local file system
@@ -466,20 +473,22 @@ pub struct FileSystemPersistence;
466
473
467
474
impl Persistence for FileSystemPersistence {
468
475
type Err = io:: Error ;
476
+ type File = tokio:: fs:: File ;
469
477
470
- fn size ( & self , path : & Path ) -> impl Future < Output = Result < u64 , Self :: Err > > {
471
- let res = std:: fs:: metadata ( path) . map ( |m| m. len ( ) ) ;
472
- async move { res }
478
+ async fn size ( & self , path : & Path ) -> Result < u64 , Self :: Err > {
479
+ tokio:: fs:: metadata ( path) . await . map ( |m| m. len ( ) )
473
480
}
474
481
475
482
fn read ( & self , path : & Path ) -> impl Future < Output = Result < Vec < u8 > , Self :: Err > > {
476
- let res = std:: fs:: read ( path) ;
477
- async move { res }
483
+ tokio:: fs:: read ( path)
478
484
}
479
485
480
486
fn create_dir_all ( & self , path : & Path ) -> impl Future < Output = Result < ( ) , Self :: Err > > {
481
- let res = std:: fs:: create_dir_all ( path) ;
482
- async move { res }
487
+ tokio:: fs:: create_dir_all ( path)
488
+ }
489
+
490
+ fn open ( & self , path : & Path ) -> impl Future < Output = Result < Self :: File , Self :: Err > > {
491
+ tokio:: fs:: File :: open ( path)
483
492
}
484
493
}
485
494
0 commit comments