Skip to content

Commit fee441d

Browse files
committed
Resolve remaining winnow 0.3 deprecations
1 parent b37a909 commit fee441d

File tree

17 files changed

+105
-91
lines changed

17 files changed

+105
-91
lines changed

gix-actor/src/identity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{signature::decode, Identity, IdentityRef};
44

55
impl<'a> IdentityRef<'a> {
66
/// Deserialize an identity from the given `data`.
7-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<Self, winnow::Err<E>>
7+
pub fn from_bytes<E>(data: &'a [u8]) -> Result<Self, winnow::error::ErrMode<E>>
88
where
99
E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>,
1010
{

gix-actor/src/signature/decode.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ pub(crate) mod function {
55
use std::cell::RefCell;
66
use winnow::{
77
branch::alt,
8-
bytes::complete::{take, take_until, take_while_m_n},
9-
character::is_digit,
8+
bytes::{take, take_until0, take_while_m_n},
109
error::{ContextError, ParseError},
11-
multi::many1_count,
10+
multi::many1,
1211
prelude::*,
13-
sequence::{terminated, tuple},
12+
sequence::terminated,
13+
stream::AsChar,
1414
};
1515

1616
use crate::{IdentityRef, SignatureRef};
@@ -26,31 +26,31 @@ pub(crate) mod function {
2626
identity,
2727
b" ",
2828
(|i| {
29-
terminated(take_until(SPACE), take(1usize))(i).and_then(|(i, v)| {
29+
terminated(take_until0(SPACE), take(1usize))(i).and_then(|(i, v)| {
3030
btoi::<SecondsSinceUnixEpoch>(v)
3131
.map(|v| (i, v))
32-
.map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))
32+
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))
3333
})
3434
})
3535
.context("<timestamp>"),
3636
alt((
37-
many1_count(b"-").map(|_| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags
38-
many1_count(b"+").map(|_| *tzsign.borrow_mut() = b'+'),
37+
many1(b"-").map(|_: ()| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags
38+
many1(b"+").map(|_: ()| *tzsign.borrow_mut() = b'+'),
3939
))
4040
.context("+|-"),
4141
(|i| {
42-
take_while_m_n(2usize, 2, is_digit)(i).and_then(|(i, v)| {
42+
take_while_m_n(2usize, 2, AsChar::is_dec_digit)(i).and_then(|(i, v)| {
4343
btoi::<OffsetInSeconds>(v)
4444
.map(|v| (i, v))
45-
.map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))
45+
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))
4646
})
4747
})
4848
.context("HH"),
4949
(|i| {
50-
take_while_m_n(1usize, 2, is_digit)(i).and_then(|(i, v)| {
50+
take_while_m_n(1usize, 2, AsChar::is_dec_digit)(i).and_then(|(i, v)| {
5151
btoi::<OffsetInSeconds>(v)
5252
.map(|v| (i, v))
53-
.map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))
53+
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))
5454
})
5555
})
5656
.context("MM"),
@@ -82,8 +82,8 @@ pub(crate) mod function {
8282
i: &'a [u8],
8383
) -> IResult<&'a [u8], IdentityRef<'a>, E> {
8484
let (i, (name, email)) = (
85-
terminated(take_until(&b" <"[..]), take(2usize)).context("<name>"),
86-
terminated(take_until(&b">"[..]), take(1usize)).context("<email>"),
85+
terminated(take_until0(&b" <"[..]), take(2usize)).context("<name>"),
86+
terminated(take_until0(&b">"[..]), take(1usize)).context("<email>"),
8787
)
8888
.context("<name> <<email>>")
8989
.parse_next(i)?;

gix-actor/src/signature/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod _ref {
55

66
impl<'a> SignatureRef<'a> {
77
/// Deserialize a signature from the given `data`.
8-
pub fn from_bytes<E>(data: &'a [u8]) -> Result<SignatureRef<'a>, winnow::Err<E>>
8+
pub fn from_bytes<E>(data: &'a [u8]) -> Result<SignatureRef<'a>, winnow::error::ErrMode<E>>
99
where
1010
E: winnow::error::ParseError<&'a [u8]> + winnow::error::ContextError<&'a [u8]>,
1111
{

gix-object/src/commit/decode.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ use std::borrow::Cow;
33
use smallvec::SmallVec;
44
use winnow::{
55
branch::alt,
6-
bytes::complete::{is_not, tag},
7-
combinator::{all_consuming, opt},
6+
bytes::{tag, take_till1},
7+
combinator::{eof, opt},
88
error::{ContextError, ParseError},
99
multi::many0,
1010
prelude::*,
11+
sequence::terminated,
1112
};
1213

1314
use crate::{parse, parse::NL, BStr, ByteSlice, CommitRef};
1415

1516
pub fn message<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
1617
if i.is_empty() {
1718
// newline + [message]
18-
return Err(winnow::Err::from_error_kind(i, winnow::error::ErrorKind::Eof)
19-
.map(|err: E| err.add_context(i, "newline + <message>")));
19+
return Err(
20+
winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Eof)
21+
.map(|err: E| err.add_context(i, "newline + <message>")),
22+
);
2023
}
2124
let (i, _) = tag(NL)
2225
.context("a newline separates headers from the message")
@@ -39,16 +42,18 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
3942
let (i, committer) = (|i| parse::header_field(i, b"committer", parse::signature))
4043
.context("committer <signature>")
4144
.parse_next(i)?;
42-
let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", is_not(NL)))
45+
let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", take_till1(NL)))
4346
.context("encoding <encoding>")
4447
.parse_next(i)?;
4548
let (i, extra_headers) = many0(alt((
4649
parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
47-
|i| parse::any_header_field(i, is_not(NL)).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr())))),
50+
|i| {
51+
parse::any_header_field(i, take_till1(NL)).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr()))))
52+
},
4853
)))
4954
.context("<field> <single-line|multi-line>")
5055
.parse_next(i)?;
51-
let (i, message) = all_consuming(message)(i)?;
56+
let (i, message) = terminated(message, eof)(i)?;
5257

5358
Ok((
5459
i,

gix-object/src/commit/message/body.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::ops::Deref;
22

33
use winnow::{
4-
bytes::complete::take_until1,
5-
combinator::all_consuming,
4+
bytes::take_until1,
5+
combinator::eof,
66
error::{ErrorKind, ParseError},
77
sequence::terminated,
88
IResult,
@@ -35,7 +35,7 @@ pub struct TrailerRef<'a> {
3535
fn parse_single_line_trailer<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (&'a BStr, &'a BStr), E> {
3636
let (value, token) = terminated(take_until1(b":".as_ref()), b": ")(i.trim_end())?;
3737
if token.trim_end().len() != token.len() || value.trim_start().len() != value.len() {
38-
Err(winnow::Err::from_error_kind(i, ErrorKind::Fail).cut())
38+
Err(winnow::error::ErrMode::from_error_kind(i, ErrorKind::Fail).cut())
3939
} else {
4040
Ok((&[], (token.as_bstr(), value.as_bstr())))
4141
}
@@ -51,7 +51,7 @@ impl<'a> Iterator for Trailers<'a> {
5151
for line in self.cursor.lines_with_terminator() {
5252
self.cursor = &self.cursor[line.len()..];
5353
if let Some(trailer) =
54-
all_consuming(parse_single_line_trailer::<()>)(line)
54+
terminated(parse_single_line_trailer::<()>, eof)(line)
5555
.ok()
5656
.map(|(_, (token, value))| TrailerRef {
5757
token: token.trim().as_bstr(),

gix-object/src/commit/message/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use winnow::{branch::alt, bytes::complete::take_till1, combinator::all_consuming, error::ParseError, prelude::*};
1+
use winnow::{branch::alt, bytes::take_till1, combinator::eof, error::ParseError, prelude::*, sequence::terminated};
22

33
use crate::bstr::{BStr, ByteSlice};
44

@@ -46,5 +46,5 @@ fn subject_and_body<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8
4646

4747
/// Returns title and body, without separator
4848
pub fn message(input: &[u8]) -> (&BStr, Option<&BStr>) {
49-
all_consuming(subject_and_body::<()>)(input).expect("cannot fail").1
49+
terminated(subject_and_body::<()>, eof)(input).expect("cannot fail").1
5050
}

gix-object/src/commit/ref_iter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use bstr::BStr;
55
use gix_hash::{oid, ObjectId};
66
use winnow::{
77
branch::alt,
8-
bytes::complete::is_not,
9-
combinator::{all_consuming, opt},
8+
bytes::take_till1,
9+
combinator::{eof, opt},
1010
prelude::*,
11+
sequence::terminated,
1112
};
1213

1314
use crate::commit::SignedData;
@@ -207,7 +208,7 @@ impl<'a> CommitRefIter<'a> {
207208
)
208209
}
209210
Encoding => {
210-
let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", is_not(NL)))
211+
let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", take_till1(NL)))
211212
.context("encoding <encoding>")
212213
.parse_next(i)?;
213214
*state = State::ExtraHeaders;
@@ -220,7 +221,7 @@ impl<'a> CommitRefIter<'a> {
220221
let (i, extra_header) = opt(alt((
221222
|i| parse::any_header_field_multi_line(i).map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Owned(o)))),
222223
|i| {
223-
parse::any_header_field(i, is_not(NL))
224+
parse::any_header_field(i, take_till1(NL))
224225
.map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr()))))
225226
},
226227
)))
@@ -235,7 +236,7 @@ impl<'a> CommitRefIter<'a> {
235236
}
236237
}
237238
Message => {
238-
let (i, message) = all_consuming(decode::message)(i)?;
239+
let (i, message) = terminated(decode::message, eof)(i)?;
239240
debug_assert!(
240241
i.is_empty(),
241242
"we should have consumed all data - otherwise iter may go forever"

gix-object/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,20 @@ pub mod decode {
278278
pub inner: ParseErrorOwned,
279279
}
280280

281-
impl<'a> From<winnow::Err<ParseError<'a>>> for Error {
282-
fn from(v: winnow::Err<ParseError<'a>>) -> Self {
281+
impl<'a> From<winnow::error::ErrMode<ParseError<'a>>> for Error {
282+
fn from(v: winnow::error::ErrMode<ParseError<'a>>) -> Self {
283283
Error {
284284
inner: match v {
285-
winnow::Err::Backtrack(err) | winnow::Err::Cut(err) => winnow::error::VerboseError {
286-
errors: err
287-
.errors
288-
.into_iter()
289-
.map(|(i, v)| (i.as_bstr().to_owned(), v))
290-
.collect(),
291-
},
292-
winnow::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"),
285+
winnow::error::ErrMode::Backtrack(err) | winnow::error::ErrMode::Cut(err) => {
286+
winnow::error::VerboseError {
287+
errors: err
288+
.errors
289+
.into_iter()
290+
.map(|(i, v)| (i.as_bstr().to_owned(), v))
291+
.collect(),
292+
}
293+
}
294+
winnow::error::ErrMode::Incomplete(_) => unreachable!("we don't have streaming parsers"),
293295
},
294296
}
295297
}
@@ -321,12 +323,12 @@ pub mod decode {
321323
pub inner: ParseErrorOwned,
322324
}
323325

324-
impl<'a> From<winnow::Err<ParseError<'a>>> for Error {
325-
fn from(v: winnow::Err<ParseError<'a>>) -> Self {
326+
impl<'a> From<winnow::error::ErrMode<ParseError<'a>>> for Error {
327+
fn from(v: winnow::error::ErrMode<ParseError<'a>>) -> Self {
326328
Error {
327329
inner: match v {
328-
winnow::Err::Backtrack(err) | winnow::Err::Cut(err) => err,
329-
winnow::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"),
330+
winnow::error::ErrMode::Backtrack(err) | winnow::error::ErrMode::Cut(err) => err,
331+
winnow::error::ErrMode::Incomplete(_) => unreachable!("we don't have streaming parsers"),
330332
},
331333
}
332334
}

gix-object/src/parse.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bstr::{BStr, BString, ByteVec};
22
use winnow::{
3-
bytes::complete::{is_not, take_until, take_while_m_n},
3+
bytes::{take_till1, take_until0, take_while_m_n},
44
combinator::peek,
55
error::{ContextError, ParseError},
6-
multi::many1_count,
6+
multi::many1,
77
prelude::*,
88
sequence::{preceded, terminated},
99
};
@@ -18,8 +18,13 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParseError<&'a [u8]> + ContextE
1818
i: &'a [u8],
1919
) -> IResult<&'a [u8], (&'a [u8], BString), E> {
2020
let (i, (k, o)) = peek((
21-
terminated(is_not(SPACE_OR_NL), SPACE),
22-
(is_not(NL), NL, many1_count(terminated((SPACE, take_until(NL)), NL))).recognize(),
21+
terminated(take_till1(SPACE_OR_NL), SPACE),
22+
(
23+
take_till1(NL),
24+
NL,
25+
many1(terminated((SPACE, take_until0(NL)), NL)).map(|()| ()),
26+
)
27+
.recognize(),
2328
))
2429
.context("name <multi-line-value>")
2530
.parse_next(i)?;
@@ -41,16 +46,16 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParseError<&'a [u8]> + ContextE
4146
pub(crate) fn header_field<'a, T, E: ParseError<&'a [u8]>>(
4247
i: &'a [u8],
4348
name: &'static [u8],
44-
parse_value: impl Fn(&'a [u8]) -> IResult<&'a [u8], T, E>,
49+
parse_value: impl FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>,
4550
) -> IResult<&'a [u8], T, E> {
4651
terminated(preceded(terminated(name, SPACE), parse_value), NL)(i)
4752
}
4853

4954
pub(crate) fn any_header_field<'a, T, E: ParseError<&'a [u8]>>(
5055
i: &'a [u8],
51-
parse_value: impl Fn(&'a [u8]) -> IResult<&'a [u8], T, E>,
56+
parse_value: impl FnMut(&'a [u8]) -> IResult<&'a [u8], T, E>,
5257
) -> IResult<&'a [u8], (&'a [u8], T), E> {
53-
terminated((terminated(is_not(SPACE_OR_NL), SPACE), parse_value), NL)(i)
58+
terminated((terminated(take_till1(SPACE_OR_NL), SPACE), parse_value), NL)(i)
5459
}
5560

5661
fn is_hex_digit_lc(b: u8) -> bool {

gix-object/src/tag/decode.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use winnow::{
22
branch::alt,
3-
bytes::complete::{tag, take_until, take_while, take_while1},
4-
character::is_alphabetic,
5-
combinator::{all_consuming, opt},
3+
bytes::{tag, take_until0, take_while0, take_while1},
4+
combinator::{eof, opt},
65
error::{ContextError, ParseError},
76
prelude::*,
8-
sequence::preceded,
7+
sequence::{preceded, terminated},
8+
stream::AsChar,
99
};
1010

1111
use crate::{parse, parse::NL, BStr, ByteSlice, TagRef};
@@ -15,11 +15,11 @@ pub fn git_tag<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]
1515
.context("object <40 lowercase hex char>")
1616
.parse_next(i)?;
1717

18-
let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(is_alphabetic)))
18+
let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(AsChar::is_alpha)))
1919
.context("type <object kind>")
2020
.parse_next(i)?;
21-
let kind =
22-
crate::Kind::from_bytes(kind).map_err(|_| winnow::Err::from_error_kind(i, winnow::error::ErrorKind::MapRes))?;
21+
let kind = crate::Kind::from_bytes(kind)
22+
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::MapRes))?;
2323

2424
let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while1(|b| b != NL[0])))
2525
.context("tag <version>")
@@ -28,7 +28,7 @@ pub fn git_tag<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(i: &'a [u8]
2828
let (i, signature) = opt(|i| parse::header_field(i, b"tagger", parse::signature))
2929
.context("tagger <signature>")
3030
.parse_next(i)?;
31-
let (i, (message, pgp_signature)) = all_consuming(message)(i)?;
31+
let (i, (message, pgp_signature)) = terminated(message, eof)(i)?;
3232
Ok((
3333
i,
3434
TagRef {
@@ -61,14 +61,14 @@ pub fn message<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (&
6161
}
6262
let (i, (message, signature)) = alt((
6363
(
64-
take_until(PGP_SIGNATURE_BEGIN),
64+
take_until0(PGP_SIGNATURE_BEGIN),
6565
preceded(
6666
NL,
6767
(
6868
&PGP_SIGNATURE_BEGIN[1..],
69-
take_until(PGP_SIGNATURE_END),
69+
take_until0(PGP_SIGNATURE_END),
7070
PGP_SIGNATURE_END,
71-
take_while(|_| true),
71+
take_while0(|_| true),
7272
)
7373
.recognize(),
7474
),

0 commit comments

Comments
 (0)