Skip to content

Commit 9ed7df0

Browse files
committed
Resolve 0.4 deprecations
1 parent 86ea47f commit 9ed7df0

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

gix-actor/src/signature/decode.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pub(crate) mod function {
55
use std::cell::RefCell;
66
use winnow::{
77
branch::alt,
8-
bytes::{take, take_until0, take_while_m_n},
8+
bytes::{take, take_until0, take_while},
9+
combinator::repeat,
910
error::{ContextError, ParseError},
10-
multi::many1,
1111
prelude::*,
1212
sequence::terminated,
1313
stream::AsChar,
@@ -36,22 +36,20 @@ pub(crate) mod function {
3636
})
3737
.context("<timestamp>"),
3838
alt((
39-
many1(b"-").map(|_: ()| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags
40-
many1(b"+").map(|_: ()| *tzsign.borrow_mut() = b'+'),
39+
repeat(1.., b"-").map(|_: ()| *tzsign.borrow_mut() = b'-'), // TODO: this should be a non-allocating consumer of consecutive tags
40+
repeat(1.., b"+").map(|_: ()| *tzsign.borrow_mut() = b'+'),
4141
))
4242
.context("+|-"),
4343
(|i| {
44-
take_while_m_n(2usize, 2, AsChar::is_dec_digit)
45-
.parse_next(i)
46-
.and_then(|(i, v)| {
47-
btoi::<OffsetInSeconds>(v)
48-
.map(|v| (i, v))
49-
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Verify))
50-
})
44+
take_while(2, AsChar::is_dec_digit).parse_next(i).and_then(|(i, v)| {
45+
btoi::<OffsetInSeconds>(v)
46+
.map(|v| (i, v))
47+
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Verify))
48+
})
5149
})
5250
.context("HH"),
5351
(|i| {
54-
take_while_m_n(1usize, 2, AsChar::is_dec_digit)
52+
take_while(1..=2, AsChar::is_dec_digit)
5553
.parse_next(i)
5654
.and_then(|(i, v)| {
5755
btoi::<OffsetInSeconds>(v)

gix-object/src/commit/decode.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use smallvec::SmallVec;
44
use winnow::{
55
branch::alt,
66
bytes::{tag, take_till1},
7+
combinator::repeat,
78
combinator::{eof, opt},
89
error::{ContextError, ParseError},
9-
multi::many0,
1010
prelude::*,
1111
sequence::terminated,
1212
};
@@ -33,7 +33,7 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
3333
let (i, tree) = (|i| parse::header_field(i, b"tree", parse::hex_hash))
3434
.context("tree <40 lowercase hex char>")
3535
.parse_next(i)?;
36-
let (i, parents): (_, Vec<_>) = many0(|i| parse::header_field(i, b"parent", parse::hex_hash))
36+
let (i, parents): (_, Vec<_>) = repeat(0.., |i| parse::header_field(i, b"parent", parse::hex_hash))
3737
.context("zero or more 'parent <40 lowercase hex char>'")
3838
.parse_next(i)?;
3939
let (i, author) = (|i| parse::header_field(i, b"author", parse::signature))
@@ -45,12 +45,16 @@ pub fn commit<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
4545
let (i, encoding) = opt(|i| parse::header_field(i, b"encoding", take_till1(NL)))
4646
.context("encoding <encoding>")
4747
.parse_next(i)?;
48-
let (i, extra_headers) = many0(alt((
49-
parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
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-
},
53-
)))
48+
let (i, extra_headers) = repeat(
49+
0..,
50+
alt((
51+
parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
52+
|i| {
53+
parse::any_header_field(i, take_till1(NL))
54+
.map(|(i, (k, o))| (i, (k.as_bstr(), Cow::Borrowed(o.as_bstr()))))
55+
},
56+
)),
57+
)
5458
.context("<field> <single-line|multi-line>")
5559
.parse_next(i)?;
5660
let (i, message) = terminated(message, eof).parse_next(i)?;

gix-object/src/parse.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bstr::{BStr, BString, ByteVec};
22
use winnow::{
3-
bytes::{take_till1, take_until0, take_while_m_n},
3+
bytes::{take_till1, take_until0, take_while},
44
combinator::peek,
5+
combinator::repeat,
56
error::{ContextError, ParseError},
6-
multi::many1,
77
prelude::*,
88
sequence::{preceded, terminated},
99
Parser,
@@ -23,7 +23,7 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParseError<&'a [u8]> + ContextE
2323
(
2424
take_till1(NL),
2525
NL,
26-
many1(terminated((SPACE, take_until0(NL)), NL)).map(|()| ()),
26+
repeat(1.., terminated((SPACE, take_until0(NL)), NL)).map(|()| ()),
2727
)
2828
.recognize(),
2929
))
@@ -64,9 +64,8 @@ fn is_hex_digit_lc(b: u8) -> bool {
6464
}
6565

6666
pub fn hex_hash<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
67-
take_while_m_n(
68-
gix_hash::Kind::shortest().len_in_hex(),
69-
gix_hash::Kind::longest().len_in_hex(),
67+
take_while(
68+
gix_hash::Kind::shortest().len_in_hex()..=gix_hash::Kind::longest().len_in_hex(),
7069
is_hex_digit_lc,
7170
)
7271
.parse_next(i)

gix-object/src/tag/decode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use winnow::{
22
branch::alt,
3-
bytes::{tag, take_until0, take_while0, take_while1},
3+
bytes::{tag, take_until0, take_while},
44
combinator::{eof, opt},
55
error::{ContextError, ParseError},
66
prelude::*,
@@ -15,13 +15,13 @@ 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(AsChar::is_alpha)))
18+
let (i, kind) = (|i| parse::header_field(i, b"type", take_while(1.., AsChar::is_alpha)))
1919
.context("type <object kind>")
2020
.parse_next(i)?;
2121
let kind = crate::Kind::from_bytes(kind)
2222
.map_err(|_| winnow::error::ErrMode::from_error_kind(i, winnow::error::ErrorKind::Verify))?;
2323

24-
let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while1(|b| b != NL[0])))
24+
let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while(1.., |b| b != NL[0])))
2525
.context("tag <version>")
2626
.parse_next(i)?;
2727

@@ -68,7 +68,7 @@ pub fn message<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], (&
6868
&PGP_SIGNATURE_BEGIN[1..],
6969
take_until0(PGP_SIGNATURE_END),
7070
PGP_SIGNATURE_END,
71-
take_while0(|_| true),
71+
take_while(0.., |_| true),
7272
)
7373
.recognize(),
7474
),

gix-object/src/tag/ref_iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bstr::BStr;
22
use gix_hash::{oid, ObjectId};
33
use winnow::{
4-
bytes::take_while1,
4+
bytes::take_while,
55
combinator::{eof, opt},
66
error::ParseError,
77
prelude::*,
@@ -75,7 +75,7 @@ impl<'a> TagRefIter<'a> {
7575
)
7676
}
7777
TargetKind => {
78-
let (i, kind) = (|i| parse::header_field(i, b"type", take_while1(AsChar::is_alpha)))
78+
let (i, kind) = (|i| parse::header_field(i, b"type", take_while(1.., AsChar::is_alpha)))
7979
.context("type <object kind>")
8080
.parse_next(i)?;
8181
let kind = Kind::from_bytes(kind)
@@ -84,7 +84,7 @@ impl<'a> TagRefIter<'a> {
8484
(i, Token::TargetKind(kind))
8585
}
8686
Name => {
87-
let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while1(|b| b != NL[0])))
87+
let (i, tag_version) = (|i| parse::header_field(i, b"tag", take_while(1.., |b| b != NL[0])))
8888
.context("tag <version>")
8989
.parse_next(i)?;
9090
*state = Tagger;

gix-object/src/tree/ref_iter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ mod decode {
118118

119119
use bstr::ByteSlice;
120120
use winnow::{
121-
bytes::{take, take_while1, take_while_m_n},
121+
bytes::{take, take_while},
122122
combinator::eof,
123+
combinator::repeat,
123124
error::ParseError,
124-
multi::many0,
125125
prelude::*,
126126
sequence::terminated,
127127
stream::AsChar,
@@ -161,10 +161,10 @@ mod decode {
161161
}
162162

163163
pub fn entry<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&[u8], EntryRef<'_>, E> {
164-
let (i, mode) = terminated(take_while_m_n(5, 6, AsChar::is_dec_digit), SPACE).parse_next(i)?;
164+
let (i, mode) = terminated(take_while(5..=6, AsChar::is_dec_digit), SPACE).parse_next(i)?;
165165
let mode = tree::EntryMode::try_from(mode)
166166
.map_err(|invalid| winnow::error::ErrMode::from_error_kind(invalid, winnow::error::ErrorKind::Verify))?;
167-
let (i, filename) = terminated(take_while1(|b| b != NULL[0]), NULL).parse_next(i)?;
167+
let (i, filename) = terminated(take_while(1.., |b| b != NULL[0]), NULL).parse_next(i)?;
168168
let (i, oid) = take(20u8).parse_next(i)?; // TODO: make this compatible with other hash lengths
169169

170170
Ok((
@@ -178,7 +178,7 @@ mod decode {
178178
}
179179

180180
pub fn tree<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], TreeRef<'a>, E> {
181-
let (i, entries) = terminated(many0(entry), eof).parse_next(i)?;
181+
let (i, entries) = terminated(repeat(0.., entry), eof).parse_next(i)?;
182182
Ok((i, TreeRef { entries }))
183183
}
184184
}

gix-ref/src/parse.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use gix_object::bstr::{BStr, ByteSlice};
2-
use winnow::{branch::alt, bytes::take_while_m_n, error::ParseError, prelude::*};
2+
use winnow::{branch::alt, bytes::take_while, error::ParseError, prelude::*};
33

44
fn is_hex_digit_lc(b: u8) -> bool {
55
matches!(b, b'0'..=b'9' | b'a'..=b'f')
@@ -9,9 +9,8 @@ fn is_hex_digit_lc(b: u8) -> bool {
99
pub fn hex_hash<'a, E: ParseError<&'a [u8]>>(i: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E> {
1010
// NOTE: It's important to be able to read all hashes, do not parameterize it. Hashes can be rejected at a later stage
1111
// if needed.
12-
take_while_m_n(
13-
gix_hash::Kind::shortest().len_in_hex(),
14-
gix_hash::Kind::longest().len_in_hex(),
12+
take_while(
13+
gix_hash::Kind::shortest().len_in_hex()..=gix_hash::Kind::longest().len_in_hex(),
1514
is_hex_digit_lc,
1615
)
1716
.parse_next(i)

gix-ref/src/store/file/log/line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> From<LineRef<'a>> for Line {
7575
pub mod decode {
7676
use gix_object::bstr::{BStr, ByteSlice};
7777
use winnow::{
78-
bytes::take_while0,
78+
bytes::take_while,
7979
combinator::opt,
8080
error::{ContextError, ParseError},
8181
prelude::*,
@@ -127,7 +127,7 @@ pub mod decode {
127127
if i.is_empty() {
128128
Ok((&[], i.as_bstr()))
129129
} else {
130-
terminated(take_while0(|c| c != b'\n'), opt(b'\n'))
130+
terminated(take_while(0.., |c| c != b'\n'), opt(b'\n'))
131131
.parse_next(i)
132132
.map(|(i, o)| (i, o.as_bstr()))
133133
}

gix-ref/src/store/file/loose/reference/decode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::convert::{TryFrom, TryInto};
22

33
use gix_hash::ObjectId;
44
use gix_object::bstr::BString;
5-
use winnow::{bytes::take_while0, combinator::opt, prelude::*, sequence::terminated};
5+
use winnow::{bytes::take_while, combinator::opt, prelude::*, sequence::terminated};
66

77
use crate::{
88
parse::{hex_hash, newline},
@@ -67,8 +67,8 @@ impl Reference {
6767

6868
fn parse(bytes: &[u8]) -> IResult<&[u8], MaybeUnsafeState> {
6969
let is_space = |b: u8| b == b' ';
70-
if let (path, Some(_ref_prefix)) = opt(terminated("ref: ", take_while0(is_space))).parse_next(bytes)? {
71-
terminated(take_while0(|b| b != b'\r' && b != b'\n'), opt(newline))
70+
if let (path, Some(_ref_prefix)) = opt(terminated("ref: ", take_while(0.., is_space))).parse_next(bytes)? {
71+
terminated(take_while(0.., |b| b != b'\r' && b != b'\n'), opt(newline))
7272
.map(|path| MaybeUnsafeState::UnvalidatedPath(path.into()))
7373
.parse_next(path)
7474
} else {

gix-ref/src/store/packed/decode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::convert::TryInto;
22

33
use gix_object::bstr::{BStr, ByteSlice};
44
use winnow::{
5-
bytes::take_while0,
5+
bytes::take_while,
66
combinator::opt,
77
error::{FromExternalError, ParseError},
88
prelude::*,
@@ -41,7 +41,7 @@ fn until_newline<'a, E>(input: &'a [u8]) -> IResult<&'a [u8], &'a BStr, E>
4141
where
4242
E: ParseError<&'a [u8]>,
4343
{
44-
terminated(take_while0(|b: u8| b != b'\r' && b != b'\n'), newline)
44+
terminated(take_while(0.., |b: u8| b != b'\r' && b != b'\n'), newline)
4545
.map(ByteSlice::as_bstr)
4646
.parse_next(input)
4747
}
@@ -71,7 +71,7 @@ pub fn reference<'a, E: ParseError<&'a [u8]> + FromExternalError<&'a [u8], crate
7171
input: &'a [u8],
7272
) -> IResult<&'a [u8], packed::Reference<'a>, E> {
7373
let (input, (target, name)) =
74-
(terminated(hex_hash, b" "), until_newline.map_res(TryInto::try_into)).parse_next(input)?;
74+
(terminated(hex_hash, b" "), until_newline.try_map(TryInto::try_into)).parse_next(input)?;
7575
let (rest, object) = opt(delimited(b"^", hex_hash, newline)).parse_next(input)?;
7676
Ok((rest, packed::Reference { name, target, object }))
7777
}

0 commit comments

Comments
 (0)