@@ -6,15 +6,12 @@ use std::{
66} ;
77
88use nom:: {
9- IResult ,
9+ IResult , Parser ,
1010 branch:: alt,
1111 bytes:: streaming:: { tag, take, take_until, take_while, take_while1} ,
12- character:: {
13- is_alphabetic,
14- streaming:: { char, digit1, newline} ,
15- } ,
12+ character:: streaming:: { char, digit1, newline} ,
1613 combinator:: { cut, map, map_res, opt} ,
17- sequence:: { delimited, separated_pair, terminated, tuple } ,
14+ sequence:: { delimited, separated_pair, terminated} ,
1815} ;
1916
2017use crate :: response:: { Error , ResponseFieldCache } ;
@@ -52,7 +49,8 @@ impl ParsedComponent {
5249 key : field_cache. insert ( k) ,
5350 value : String :: from ( v) ,
5451 } ) ,
55- ) ) ( i)
52+ ) )
53+ . parse ( i)
5654 }
5755}
5856
@@ -73,25 +71,27 @@ pub(crate) fn greeting(i: &[u8]) -> IResult<&[u8], &str> {
7371 tag ( "OK MPD " ) ,
7472 map_res ( take_while1 ( |c| c != b'\n' ) , from_utf8) ,
7573 newline,
76- ) ( i)
74+ )
75+ . parse ( i)
7776}
7877
7978/// Recognize and parse an unsigned ASCII-encoded number
8079fn number < O : FromStr > ( i : & [ u8 ] ) -> IResult < & [ u8 ] , O > {
81- map_res ( map_res ( digit1, from_utf8) , str:: parse) ( i)
80+ map_res ( map_res ( digit1, from_utf8) , str:: parse) . parse ( i)
8281}
8382
8483/// Parse an error response.
8584fn error ( i : & [ u8 ] ) -> IResult < & [ u8 ] , RawError < ' _ > > {
8685 let ( remaining, ( ( code, index) , command, message) ) = delimited (
8786 tag ( "ACK " ) ,
88- tuple ( (
87+ (
8988 terminated ( error_code_and_index, char ( ' ' ) ) ,
9089 terminated ( error_current_command, char ( ' ' ) ) ,
9190 map_res ( take_while ( |b| b != b'\n' ) , from_utf8) ,
92- ) ) ,
91+ ) ,
9392 newline,
94- ) ( i) ?;
93+ )
94+ . parse ( i) ?;
9595
9696 Ok ( (
9797 remaining,
@@ -110,31 +110,34 @@ fn error_code_and_index(i: &[u8]) -> IResult<&[u8], (u64, u64)> {
110110 char ( '[' ) ,
111111 separated_pair ( number, char ( '@' ) , number) ,
112112 char ( ']' ) ,
113- ) ( i)
113+ )
114+ . parse ( i)
114115}
115116
116117/// Recognize the current command in an error, `None` if empty.
117118fn error_current_command ( i : & [ u8 ] ) -> IResult < & [ u8 ] , Option < & str > > {
118119 delimited (
119120 char ( '{' ) ,
120121 opt ( map_res (
121- take_while1 ( |b| is_alphabetic ( b ) || b == b'_' ) ,
122+ take_while1 ( |b : u8 | b . is_ascii_alphabetic ( ) || b == b'_' ) ,
122123 from_utf8,
123124 ) ) ,
124125 char ( '}' ) ,
125- ) ( i)
126+ )
127+ . parse ( i)
126128}
127129
128130/// Recognize a single key-value pair
129131fn key_value_field ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( & str , & str ) > {
130132 separated_pair (
131133 map_res (
132- take_while1 ( |b| is_alphabetic ( b ) || b == b'_' || b == b'-' ) ,
134+ take_while1 ( |b : u8 | b . is_ascii_alphabetic ( ) || b == b'_' || b == b'-' ) ,
133135 from_utf8,
134136 ) ,
135137 tag ( ": " ) ,
136138 map_res ( field_value, from_utf8) ,
137- ) ( i)
139+ )
140+ . parse ( i)
138141}
139142
140143fn field_value ( i : & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
@@ -144,14 +147,14 @@ fn field_value(i: &[u8]) -> IResult<&[u8], &[u8]> {
144147
145148/// Recognize the header of a binary section
146149fn binary_prefix ( i : & [ u8 ] ) -> IResult < & [ u8 ] , usize > {
147- delimited ( tag ( "binary: " ) , number, newline) ( i)
150+ delimited ( tag ( "binary: " ) , number, newline) . parse ( i)
148151}
149152
150153/// Recognize a binary field
151154fn binary_field ( i : & [ u8 ] ) -> IResult < & [ u8 ] , & [ u8 ] > {
152155 let ( i, length) = binary_prefix ( i) ?;
153156
154- cut ( terminated ( take ( length) , newline) ) ( i)
157+ cut ( terminated ( take ( length) , newline) ) . parse ( i)
155158}
156159
157160#[ cfg( test) ]
0 commit comments