1
1
use std:: convert:: TryFrom ;
2
2
3
3
use bstr:: ByteSlice ;
4
- use nom:: {
5
- bytes:: complete:: { tag, take_till, take_till1} ,
6
- combinator:: { map_res, opt} ,
7
- sequence:: { preceded, terminated} ,
4
+ use winnow:: {
5
+ combinator:: opt,
6
+ combinator:: { preceded, terminated} ,
7
+ prelude:: * ,
8
+ token:: { tag, take_till0, take_till1} ,
8
9
} ;
9
10
10
11
/// The information usually found in remote progress messages as sent by a git server during
@@ -25,8 +26,8 @@ pub struct RemoteProgress<'a> {
25
26
26
27
impl < ' a > RemoteProgress < ' a > {
27
28
/// Parse the progress from a typical git progress `line` as sent by the remote.
28
- pub fn from_bytes ( line : & [ u8 ] ) -> Option < RemoteProgress < ' _ > > {
29
- parse_progress ( line) . ok ( ) . and_then ( |( _ , r ) | {
29
+ pub fn from_bytes ( mut line : & [ u8 ] ) -> Option < RemoteProgress < ' _ > > {
30
+ parse_progress ( & mut line) . ok ( ) . and_then ( |r | {
30
31
if r. percent . is_none ( ) && r. step . is_none ( ) && r. max . is_none ( ) {
31
32
None
32
33
} else {
@@ -73,36 +74,36 @@ impl<'a> RemoteProgress<'a> {
73
74
}
74
75
}
75
76
76
- fn parse_number ( i : & [ u8 ] ) -> nom:: IResult < & [ u8 ] , usize > {
77
- map_res ( take_till ( |c : u8 | !c. is_ascii_digit ( ) ) , btoi:: btoi) ( i)
77
+ fn parse_number ( i : & mut & [ u8 ] ) -> PResult < usize , ( ) > {
78
+ take_till0 ( |c : u8 | !c. is_ascii_digit ( ) )
79
+ . try_map ( btoi:: btoi)
80
+ . parse_next ( i)
78
81
}
79
82
80
- fn next_optional_percentage ( i : & [ u8 ] ) -> nom :: IResult < & [ u8 ] , Option < u32 > > {
83
+ fn next_optional_percentage ( i : & mut & [ u8 ] ) -> PResult < Option < u32 > , ( ) > {
81
84
opt ( terminated (
82
85
preceded (
83
- take_till ( |c : u8 | c. is_ascii_digit ( ) ) ,
84
- map_res ( parse_number, u32:: try_from) ,
86
+ take_till0 ( |c : u8 | c. is_ascii_digit ( ) ) ,
87
+ parse_number. try_map ( u32:: try_from) ,
85
88
) ,
86
89
tag ( b"%" ) ,
87
- ) ) ( i)
90
+ ) )
91
+ . parse_next ( i)
88
92
}
89
93
90
- fn next_optional_number ( i : & [ u8 ] ) -> nom :: IResult < & [ u8 ] , Option < usize > > {
91
- opt ( preceded ( take_till ( |c : u8 | c. is_ascii_digit ( ) ) , parse_number) ) ( i)
94
+ fn next_optional_number ( i : & mut & [ u8 ] ) -> PResult < Option < usize > , ( ) > {
95
+ opt ( preceded ( take_till0 ( |c : u8 | c. is_ascii_digit ( ) ) , parse_number) ) . parse_next ( i)
92
96
}
93
97
94
- fn parse_progress ( line : & [ u8 ] ) -> nom:: IResult < & [ u8 ] , RemoteProgress < ' _ > > {
95
- let ( i, action) = take_till1 ( |c| c == b':' ) ( line) ?;
96
- let ( i, percent) = next_optional_percentage ( i) ?;
97
- let ( i, step) = next_optional_number ( i) ?;
98
- let ( i, max) = next_optional_number ( i) ?;
99
- Ok ( (
100
- i,
101
- RemoteProgress {
102
- action : action. into ( ) ,
103
- percent,
104
- step,
105
- max,
106
- } ,
107
- ) )
98
+ fn parse_progress < ' i > ( line : & mut & ' i [ u8 ] ) -> PResult < RemoteProgress < ' i > , ( ) > {
99
+ let action = take_till1 ( |c| c == b':' ) . parse_next ( line) ?;
100
+ let percent = next_optional_percentage. parse_next ( line) ?;
101
+ let step = next_optional_number. parse_next ( line) ?;
102
+ let max = next_optional_number. parse_next ( line) ?;
103
+ Ok ( RemoteProgress {
104
+ action : action. into ( ) ,
105
+ percent,
106
+ step,
107
+ max,
108
+ } )
108
109
}
0 commit comments