File tree Expand file tree Collapse file tree 3 files changed +17
-40
lines changed
Expand file tree Collapse file tree 3 files changed +17
-40
lines changed Original file line number Diff line number Diff line change 2727 R : io:: Read ,
2828{
2929 match state {
30- State :: AtStart => {
31- if read_skipping_ws ( & mut reader) ? == b'[' {
32- // read the next char to see if the array is empty
30+ State :: AtStart => match read_skipping_ws ( & mut reader) ? {
31+ b'[' => {
3332 let peek = read_skipping_ws ( & mut reader) ?;
3433 if peek == b']' {
3534 * state = State :: Finished ;
@@ -38,11 +37,12 @@ where
3837 * state = State :: AtMiddle ;
3938 deserialize_single ( io:: Cursor :: new ( [ peek] ) . chain ( reader) ) . map ( Some )
4039 }
41- } else {
40+ }
41+ _ => {
4242 * state = State :: Failed ;
4343 Err ( serde:: de:: Error :: custom ( "expected `[`" ) )
4444 }
45- }
45+ } ,
4646 State :: AtMiddle => match read_skipping_ws ( & mut reader) ? {
4747 b',' => deserialize_single ( reader) . map ( Some ) ,
4848 b']' => {
5454 Err ( serde:: de:: Error :: custom ( "expected `,` or `]`" ) )
5555 }
5656 } ,
57- State :: Finished => Ok ( None ) ,
58- State :: Failed => Ok ( None ) ,
57+ State :: Finished | State :: Failed => Ok ( None ) ,
5958 }
6059}
6160
7473fn read_skipping_ws ( mut reader : impl io:: Read ) -> Result < u8 > {
7574 loop {
7675 let mut byte = 0u8 ;
77- if let Err ( io) = reader. read_exact ( std:: slice:: from_mut ( & mut byte) ) {
78- return Err ( Error :: io ( io) ) ;
79- }
76+ reader
77+ . read_exact ( std:: slice:: from_mut ( & mut byte) )
78+ . map_err ( Error :: io) ?;
79+
8080 if !byte. is_ascii_whitespace ( ) {
8181 return Ok ( byte) ;
8282 }
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ pub struct Entry {
4343 pub output : Option < std:: path:: PathBuf > ,
4444}
4545
46+ /// Serialize entries from the iterator into a Writer object.
4647pub fn write (
4748 writer : impl std:: io:: Write ,
4849 entries : impl Iterator < Item = Entry > ,
@@ -55,6 +56,7 @@ pub fn write(
5556 seq. end ( )
5657}
5758
59+ /// Deserialize entries from the Reader object into an iterator of Entries.
5860pub fn read ( reader : impl std:: io:: Read ) -> impl Iterator < Item = Result < Entry , Error > > {
5961 iterator:: iter_json_array ( reader)
6062}
Original file line number Diff line number Diff line change @@ -74,36 +74,11 @@ impl<'de> Deserialize<'de> for Entry {
7474
7575 while let Some ( key) = map. next_key ( ) ? {
7676 match key {
77- Field :: Directory => {
78- if directory. is_some ( ) {
79- return Err ( de:: Error :: duplicate_field ( "directory" ) ) ;
80- }
81- directory = Some ( map. next_value ( ) ?) ;
82- }
83- Field :: File => {
84- if file. is_some ( ) {
85- return Err ( de:: Error :: duplicate_field ( "file" ) ) ;
86- }
87- file = Some ( map. next_value ( ) ?) ;
88- }
89- Field :: Command => {
90- if command. is_some ( ) {
91- return Err ( de:: Error :: duplicate_field ( "command" ) ) ;
92- }
93- command = Some ( map. next_value ( ) ?) ;
94- }
95- Field :: Arguments => {
96- if arguments. is_some ( ) {
97- return Err ( de:: Error :: duplicate_field ( "arguments" ) ) ;
98- }
99- arguments = Some ( map. next_value ( ) ?) ;
100- }
101- Field :: Output => {
102- if output. is_some ( ) {
103- return Err ( de:: Error :: duplicate_field ( "output" ) ) ;
104- }
105- output = Some ( map. next_value ( ) ?) ;
106- }
77+ Field :: Directory => directory = Some ( map. next_value ( ) ?) ,
78+ Field :: File => file = Some ( map. next_value ( ) ?) ,
79+ Field :: Command => command = Some ( map. next_value ( ) ?) ,
80+ Field :: Arguments => arguments = Some ( map. next_value ( ) ?) ,
81+ Field :: Output => output = Some ( map. next_value ( ) ?) ,
10782 }
10883 }
10984 let directory = directory. ok_or_else ( || de:: Error :: missing_field ( "directory" ) ) ?;
You can’t perform that action at this time.
0 commit comments