1
1
use crate :: { CompressFile , DownloadSource , Event , checksum:: ChecksumValidator } ;
2
2
use std:: {
3
3
fs:: Permissions ,
4
- future:: Future ,
5
4
io:: { self , ErrorKind , SeekFrom } ,
6
5
os:: unix:: fs:: PermissionsExt ,
7
6
path:: Path ,
@@ -101,11 +100,7 @@ pub enum SingleDownloadError {
101
100
}
102
101
103
102
impl SingleDownloader < ' _ > {
104
- pub ( crate ) async fn try_download < F , Fut > ( self , callback : & F ) -> DownloadResult
105
- where
106
- F : Fn ( Event ) -> Fut ,
107
- Fut : Future < Output = ( ) > ,
108
- {
103
+ pub ( crate ) async fn try_download ( self , callback : & impl AsyncFn ( Event ) ) -> DownloadResult {
109
104
let mut sources = self . entry . source . clone ( ) ;
110
105
assert ! ( !sources. is_empty( ) ) ;
111
106
@@ -164,16 +159,12 @@ impl SingleDownloader<'_> {
164
159
}
165
160
166
161
/// Download file with retry (http)
167
- async fn try_http_download < F , Fut > (
162
+ async fn try_http_download (
168
163
& self ,
169
164
source : & DownloadSource ,
170
165
auth : & Option < ( String , String ) > ,
171
- callback : & F ,
172
- ) -> Result < bool , SingleDownloadError >
173
- where
174
- F : Fn ( Event ) -> Fut ,
175
- Fut : Future < Output = ( ) > ,
176
- {
166
+ callback : & impl AsyncFn ( Event ) ,
167
+ ) -> Result < bool , SingleDownloadError > {
177
168
let mut times = 1 ;
178
169
let mut allow_resume = self . entry . allow_resume ;
179
170
loop {
@@ -210,17 +201,13 @@ impl SingleDownloader<'_> {
210
201
}
211
202
}
212
203
213
- async fn http_download < F , Fut > (
204
+ async fn http_download (
214
205
& self ,
215
206
allow_resume : bool ,
216
207
source : & DownloadSource ,
217
208
auth : & Option < ( String , String ) > ,
218
- callback : & F ,
219
- ) -> Result < bool , SingleDownloadError >
220
- where
221
- F : Fn ( Event ) -> Fut ,
222
- Fut : Future < Output = ( ) > ,
223
- {
209
+ callback : & impl AsyncFn ( Event ) ,
210
+ ) -> Result < bool , SingleDownloadError > {
224
211
let file = self . entry . dir . join ( & * self . entry . filename ) ;
225
212
let file_exist = file. exists ( ) ;
226
213
let mut file_size = file. metadata ( ) . ok ( ) . map ( |x| x. len ( ) ) . unwrap_or ( 0 ) ;
@@ -588,16 +575,12 @@ impl SingleDownloader<'_> {
588
575
}
589
576
590
577
/// Download local source file
591
- async fn download_local < F , Fut > (
578
+ async fn download_local (
592
579
& self ,
593
580
source : & DownloadSource ,
594
581
as_symlink : bool ,
595
- callback : & F ,
596
- ) -> Result < bool , SingleDownloadError >
597
- where
598
- F : Fn ( Event ) -> Fut ,
599
- Fut : Future < Output = ( ) > ,
600
- {
582
+ callback : & impl AsyncFn ( Event ) ,
583
+ ) -> Result < bool , SingleDownloadError > {
601
584
debug ! ( "{:?}" , self . entry) ;
602
585
let msg = self . progress_msg ( ) ;
603
586
@@ -701,16 +684,12 @@ impl SingleDownloader<'_> {
701
684
Ok ( true )
702
685
}
703
686
704
- async fn checksum_local < F , Fut > (
687
+ async fn checksum_local (
705
688
& self ,
706
- callback : & F ,
689
+ callback : & impl AsyncFn ( Event ) ,
707
690
url_path : & Path ,
708
691
hash : & crate :: checksum:: Checksum ,
709
- ) -> Result < ( ) , SingleDownloadError >
710
- where
711
- F : Fn ( Event ) -> Fut ,
712
- Fut : Future < Output = ( ) > ,
713
- {
692
+ ) -> Result < ( ) , SingleDownloadError > {
714
693
let mut f = fs:: File :: open ( url_path) . await . context ( OpenSnafu ) ?;
715
694
let ( size, finish) = checksum ( callback, & mut f, & mut hash. get_validator ( ) ) . await ;
716
695
@@ -724,11 +703,11 @@ impl SingleDownloader<'_> {
724
703
}
725
704
}
726
705
727
- async fn checksum < F , Fut > ( callback : & F , f : & mut File , v : & mut ChecksumValidator ) -> ( u64 , bool )
728
- where
729
- F : Fn ( Event ) -> Fut ,
730
- Fut : Future < Output = ( ) > ,
731
- {
706
+ async fn checksum (
707
+ callback : & impl AsyncFn ( Event ) ,
708
+ f : & mut File ,
709
+ v : & mut ChecksumValidator ,
710
+ ) -> ( u64 , bool ) {
732
711
let mut reader = tokio:: io:: BufReader :: with_capacity ( READ_FILE_BUFSIZE , f) ;
733
712
734
713
let mut read = 0 ;
0 commit comments