33
33
{
34
34
/// Iterator over the shard files in the set, opening readers.
35
35
shard_reader_iter :
36
- Box < dyn Iterator < Item = Result < UnsortedShardFileReader < T , S > , Error > > + Send > ,
36
+ Box < dyn Iterator < Item = Result < UnsortedShardFileReader < T , S > , Error > > + Send + Sync > ,
37
37
38
38
/// Iterator over the current shard file.
39
39
active_shard_reader : Option < UnsortedShardFileReader < T , S > > ,
@@ -42,22 +42,16 @@ where
42
42
impl < T , S > UnsortedShardReader < T , S >
43
43
where
44
44
T : DeserializeOwned ,
45
- <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send ,
45
+ <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send + Sync + ' static ,
46
46
S : SortKey < T > ,
47
47
{
48
48
/// Open a single shard file.
49
- pub fn open < P : AsRef < Path > > ( shard_file : P ) -> Self
50
- where
51
- <S as SortKey < T > >:: Key : ' static ,
52
- {
49
+ pub fn open < P : AsRef < Path > > ( shard_file : P ) -> Self {
53
50
Self :: open_set ( & [ shard_file] )
54
51
}
55
52
56
53
/// Open a set of shard files.
57
- pub fn open_set < P : AsRef < Path > > ( shard_files : & [ P ] ) -> Self
58
- where
59
- <S as SortKey < T > >:: Key : ' static ,
60
- {
54
+ pub fn open_set < P : AsRef < Path > > ( shard_files : & [ P ] ) -> Self {
61
55
let reader_iter = shard_files
62
56
. iter ( )
63
57
. map ( |f| f. as_ref ( ) . into ( ) )
71
65
}
72
66
73
67
/// Compute the total number of elements in this set of shard files.
74
- pub fn len < P : AsRef < Path > > ( shard_files : & [ P ] ) -> Result < usize , Error >
75
- where
76
- <S as SortKey < T > >:: Key : ' static ,
77
- {
68
+ pub fn len < P : AsRef < Path > > ( shard_files : & [ P ] ) -> Result < usize , Error > {
78
69
// Create a set reader, and consume all the files, just getting counts.
79
70
let files_reader = Self :: open_set ( shard_files) ;
80
71
let mut count = 0 ;
@@ -138,7 +129,7 @@ where
138
129
impl < T , S > Iterator for UnsortedShardReader < T , S >
139
130
where
140
131
T : DeserializeOwned ,
141
- <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send ,
132
+ <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send + Sync + ' static ,
142
133
S : SortKey < T > ,
143
134
{
144
135
type Item = Result < T , Error > ;
@@ -178,23 +169,20 @@ where
178
169
S : SortKey < T > ,
179
170
{
180
171
count : usize ,
181
- file_index_iter : Box < dyn Iterator < Item = KeylessShardRecord > + Send > ,
172
+ file_index_iter : Box < dyn Iterator < Item = KeylessShardRecord > + Send + Sync > ,
182
173
shard_iter : Option < UnsortedShardIter < T > > ,
183
174
phantom : PhantomData < S > ,
184
175
}
185
176
186
177
impl < T , S > UnsortedShardFileReader < T , S >
187
178
where
188
179
T : DeserializeOwned ,
189
- <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send ,
180
+ <S as SortKey < T > >:: Key : Clone + Ord + DeserializeOwned + Send + Sync + ' static ,
190
181
S : SortKey < T > ,
191
182
{
192
183
/// Create a unsorted reader for a single shard file.
193
184
/// Return Ok(None) if the specified shard file is empty.
194
- pub fn new ( path : & Path ) -> Result < Option < Self > , Error >
195
- where
196
- <S as SortKey < T > >:: Key : ' static ,
197
- {
185
+ pub fn new ( path : & Path ) -> Result < Option < Self > , Error > {
198
186
let reader = ShardReaderSingle :: < T , S > :: open ( path) ?;
199
187
let count = reader. len ( ) ;
200
188
let mut file_index_iter = reader. index . into_iter ( ) . map ( |r| KeylessShardRecord {
@@ -348,3 +336,11 @@ struct SkipResult {
348
336
skipped : usize ,
349
337
exhausted : bool ,
350
338
}
339
+
340
+ /// Ensure that readers are Sync.
341
+ #[ allow( dead_code) ]
342
+ const fn assert_readers_are_sync ( ) {
343
+ const fn takes_sync < T : Sync > ( ) { }
344
+ takes_sync :: < UnsortedShardFileReader < usize , DefaultSort > > ( ) ;
345
+ takes_sync :: < UnsortedShardReader < usize , DefaultSort > > ( ) ;
346
+ }
0 commit comments