@@ -14,7 +14,7 @@ pub(crate) fn id_from_url(url: &str) -> io::Result<String> {
1414 None => url_obj
1515 . path_segments ( )
1616 . to_result ( INVALID_URL ) ?
17- . last ( )
17+ . next_back ( )
1818 . to_result ( INVALID_URL ) ?
1919 . to_string ( ) ,
2020 } )
@@ -41,49 +41,42 @@ pub(crate) fn sanitize_url(url: &str) -> io::Result<String> {
4141 const PERIOD_TAG : & str = "atm_aiy" ;
4242 let url_obj = Url :: try_from ( url) . to_result ( ) ?;
4343 match url_obj. query_pairs ( ) . find ( |x| x. 0 == PERIOD_TAG ) {
44- Some ( x) => Ok ( std:: format!( "{base_url}&{PERIOD_TAG}={}" , x. 1 . to_string ( ) ) ) ,
44+ Some ( x) => Ok ( std:: format!( "{base_url}&{PERIOD_TAG}={}" , x. 1 ) ) ,
4545 None => Ok ( base_url) ,
4646 }
4747}
4848
49- // Methods to convert between option/result types for error propogation .
49+ // Methods to convert between option/result types for error propagation .
5050
5151pub ( crate ) trait ToResult < T > {
52- ///
5352 fn to_result ( self ) -> std:: io:: Result < T > ;
5453}
5554
5655impl < T , E : Display > ToResult < T > for std:: result:: Result < T , E > {
5756 fn to_result ( self ) -> std:: io:: Result < T > {
5857 match self {
5958 Ok ( x) => Ok ( x) ,
60- Err ( x) => Err ( std:: io:: Error :: new ( io :: ErrorKind :: Other , x. to_string ( ) ) ) ,
59+ Err ( x) => Err ( std:: io:: Error :: other ( x. to_string ( ) ) ) ,
6160 }
6261 }
6362}
6463
6564pub ( crate ) trait ToResultErrorMessage < T > {
66- ///
6765 fn to_result ( self , msg : & str ) -> std:: io:: Result < T > ;
6866}
6967
7068impl < T > ToResultErrorMessage < T > for Option < T > {
7169 fn to_result ( self , msg : & str ) -> std:: io:: Result < T > {
7270 match self {
7371 Some ( x) => Ok ( x) ,
74- None => Err ( std:: io:: Error :: new ( io :: ErrorKind :: Other , msg) ) ,
72+ None => Err ( std:: io:: Error :: other ( msg. to_string ( ) ) ) ,
7573 }
7674 }
7775}
7876
7977/// Generate filename for image.
8078pub ( crate ) fn generate_image_filename ( page_number : & usize , page_id : & str , ext : & str ) -> String {
81- std:: format!(
82- "{0}-{1}.{2}" ,
83- std:: format!( "{:0>5}" , page_number) ,
84- page_id,
85- ext
86- )
79+ std:: format!( "{:0>5}-{page_id}.{ext}" , page_number)
8780}
8881
8982/// Determine image extension by the content header.
@@ -109,7 +102,7 @@ pub(crate) fn get_image_ext(res: &reqwest::blocking::Response) -> io::Result<Str
109102/// Determine image extension by the content header.
110103pub ( crate ) fn try_download ( url : & str , mut attempts : u32 ) -> io:: Result < reqwest:: blocking:: Response > {
111104 let indefinite = attempts == 0 ;
112- let mut res: io:: Result < reqwest:: blocking:: Response > = Err ( io:: Error :: new ( io :: ErrorKind :: Other , "" ) ) ;
105+ let mut res: io:: Result < reqwest:: blocking:: Response > = Err ( io:: Error :: other ( "" ) ) ;
113106 while indefinite || attempts > 0 {
114107 res = reqwest:: blocking:: get ( url) . to_result ( ) ;
115108 if let Ok ( res) = res {
0 commit comments