@@ -21,8 +21,8 @@ pub enum State {
2121
2222// Make sure iced can use our download stream
2323impl < H , I > iced_native:: subscription:: Recipe < H , I > for Download
24- where
25- H : std:: hash:: Hasher ,
24+ where
25+ H : std:: hash:: Hasher ,
2626{
2727 type Output = ( String , Progress ) ;
2828
@@ -31,7 +31,10 @@ impl<H, I> iced_native::subscription::Recipe<H, I> for Download
3131 self . url . hash ( state) ;
3232 }
3333
34- fn stream ( self : Box < Self > , _input : BoxStream < ' static , I > ) -> BoxStream < ' static , Self :: Output > {
34+ fn stream (
35+ self : Box < Self > ,
36+ _input : BoxStream < ' static , I > ,
37+ ) -> BoxStream < ' static , Self :: Output > {
3538 Box :: pin ( stream:: unfold (
3639 State :: Ready ( self . url . to_string ( ) ) ,
3740 |state| async move {
@@ -49,10 +52,15 @@ impl<H, I> iced_native::subscription::Recipe<H, I> for Download
4952 } ,
5053 ) )
5154 } else {
52- Some ( ( ( url, Progress :: Errored ) , State :: Finished ) )
55+ Some ( (
56+ ( url, Progress :: Errored ) ,
57+ State :: Finished ,
58+ ) )
5359 }
5460 }
55- Err ( _) => Some ( ( ( url, Progress :: Errored ) , State :: Finished ) ) ,
61+ Err ( _) => {
62+ Some ( ( ( url, Progress :: Errored ) , State :: Finished ) )
63+ }
5664 } ,
5765 State :: Downloading {
5866 url,
@@ -61,11 +69,16 @@ impl<H, I> iced_native::subscription::Recipe<H, I> for Download
6169 mut bytes,
6270 } => match response. chunk ( ) . await {
6371 Ok ( Some ( chunk) ) => {
64- let downloaded = bytes. len ( ) as u64 + chunk. len ( ) as u64 ;
65- let percentage = ( downloaded as f32 / total as f32 ) * 100.0 ;
72+ let downloaded =
73+ bytes. len ( ) as u64 + chunk. len ( ) as u64 ;
74+ let percentage =
75+ ( downloaded as f32 / total as f32 ) * 100.0 ;
6676 bytes. put ( chunk) ;
6777 Some ( (
68- ( url. to_string ( ) , Progress :: Advanced ( percentage) ) ,
78+ (
79+ url. to_string ( ) ,
80+ Progress :: Advanced ( percentage) ,
81+ ) ,
6982 State :: Downloading {
7083 url,
7184 response,
@@ -74,8 +87,13 @@ impl<H, I> iced_native::subscription::Recipe<H, I> for Download
7487 } ,
7588 ) )
7689 }
77- Ok ( None ) => Some ( ( ( url, Progress :: Finished ( bytes) ) , State :: Finished ) ) ,
78- Err ( _) => Some ( ( ( url, Progress :: Errored ) , State :: Finished ) ) ,
90+ Ok ( None ) => Some ( (
91+ ( url, Progress :: Finished ( bytes) ) ,
92+ State :: Finished ,
93+ ) ) ,
94+ Err ( _) => {
95+ Some ( ( ( url, Progress :: Errored ) , State :: Finished ) )
96+ }
7997 } ,
8098 State :: Finished => {
8199 // We do not let the stream die, as it would start a
0 commit comments