1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use super::SourceKey;
use auto_impl::auto_impl;
use digest::Digest;
use dyn_clonable::dyn_clone::{clone_trait_object, DynClone};
use std::{
fmt::Debug,
io::{Read, Result as IoResult, Write},
};
#[cfg(feature = "async")]
use futures::{
future::BoxFuture,
io::{AsyncRead, AsyncWrite},
};
#[auto_impl(&, &mut, Box, Rc, Arc)]
pub trait ResumableRecorder: DynClone + Debug + Sync + Send {
type HashAlgorithm: Digest;
fn open_for_read(
&self,
source_key: &SourceKey<Self::HashAlgorithm>,
) -> IoResult<Box<dyn ReadOnlyResumableRecorderMedium>>;
fn open_for_append(
&self,
source_key: &SourceKey<Self::HashAlgorithm>,
) -> IoResult<Box<dyn AppendOnlyResumableRecorderMedium>>;
fn open_for_create_new(
&self,
source_key: &SourceKey<Self::HashAlgorithm>,
) -> IoResult<Box<dyn AppendOnlyResumableRecorderMedium>>;
fn delete(&self, source_key: &SourceKey<Self::HashAlgorithm>) -> IoResult<()>;
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn open_for_async_read<'a>(
&'a self,
source_key: &'a SourceKey<Self::HashAlgorithm>,
) -> BoxFuture<'a, IoResult<Box<dyn ReadOnlyAsyncResumableRecorderMedium>>>;
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn open_for_async_append<'a>(
&'a self,
source_key: &'a SourceKey<Self::HashAlgorithm>,
) -> BoxFuture<'a, IoResult<Box<dyn AppendOnlyAsyncResumableRecorderMedium>>>;
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn open_for_async_create_new<'a>(
&'a self,
source_key: &'a SourceKey<Self::HashAlgorithm>,
) -> BoxFuture<'a, IoResult<Box<dyn AppendOnlyAsyncResumableRecorderMedium>>>;
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
fn async_delete<'a>(&'a self, source_key: &'a SourceKey<Self::HashAlgorithm>) -> BoxFuture<'a, IoResult<()>>;
}
clone_trait_object!(<H> ResumableRecorder<HashAlgorithm=H> where H: Digest);
pub trait ReadOnlyResumableRecorderMedium: Read + Debug + Sync + Send {}
impl<T: Read + Debug + Sync + Send> ReadOnlyResumableRecorderMedium for T {}
pub trait AppendOnlyResumableRecorderMedium: Write + Debug + Sync + Send {}
impl<T: Write + Debug + Sync + Send> AppendOnlyResumableRecorderMedium for T {}
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
pub trait ReadOnlyAsyncResumableRecorderMedium: AsyncRead + Unpin + Debug + Sync + Send {}
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
impl<T: AsyncRead + Unpin + Debug + Sync + Send> ReadOnlyAsyncResumableRecorderMedium for T {}
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
pub trait AppendOnlyAsyncResumableRecorderMedium: AsyncWrite + Unpin + Debug + Sync + Send {}
#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
impl<T: AsyncWrite + Unpin + Debug + Sync + Send> AppendOnlyAsyncResumableRecorderMedium for T {}
mod dummy;
mod file;
pub use dummy::{DummyResumableRecorder, DummyResumableRecorderMedium};
pub use file::FileSystemResumableRecorder;