Skip to content

Commit 0884bf8

Browse files
Gealepage
andauthored
Remove hidden map! and call! macros (#1601)
They are not needed anymore to implement some combinators Co-authored-by: Ed Page <eopage@gmail.com>
1 parent fadde7c commit 0884bf8

File tree

2 files changed

+58
-82
lines changed

2 files changed

+58
-82
lines changed

src/number/complete.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,6 @@ use crate::traits::{
1313
AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
1414
};
1515

16-
#[doc(hidden)]
17-
macro_rules! map(
18-
// Internal parser, do not use directly
19-
(__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
20-
$crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
21-
);
22-
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
23-
map!(__impl $i, $submac!($($args)*), $g)
24-
);
25-
($i:expr, $f:expr, $g:expr) => (
26-
map!(__impl $i, call!($f), $g)
27-
);
28-
);
29-
30-
#[doc(hidden)]
31-
macro_rules! call (
32-
($i:expr, $fun:expr) => ( $fun( $i ) );
33-
($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
34-
);
35-
3616
/// Recognizes an unsigned 1 byte integer.
3717
///
3818
/// *Complete version*: Returns an error if there is not enough input data.
@@ -248,7 +228,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
248228
where
249229
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
250230
{
251-
map!(input, be_u8, |x| x as i8)
231+
be_u8.map(|x| x as i8).parse(input)
252232
}
253233

254234
/// Recognizes a big endian signed 2 bytes integer.
@@ -271,7 +251,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
271251
where
272252
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
273253
{
274-
map!(input, be_u16, |x| x as i16)
254+
be_u16.map(|x| x as i16).parse(input)
275255
}
276256

277257
/// Recognizes a big endian signed 3 bytes integer.
@@ -295,11 +275,15 @@ where
295275
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
296276
{
297277
// Same as the unsigned version but we need to sign-extend manually here
298-
map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
299-
(x | 0xff_00_00_00) as i32
300-
} else {
301-
x as i32
302-
})
278+
be_u24
279+
.map(|x| {
280+
if x & 0x80_00_00 != 0 {
281+
(x | 0xff_00_00_00) as i32
282+
} else {
283+
x as i32
284+
}
285+
})
286+
.parse(input)
303287
}
304288

305289
/// Recognizes a big endian signed 4 bytes integer.
@@ -322,7 +306,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
322306
where
323307
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
324308
{
325-
map!(input, be_u32, |x| x as i32)
309+
be_u32.map(|x| x as i32).parse(input)
326310
}
327311

328312
/// Recognizes a big endian signed 8 bytes integer.
@@ -345,7 +329,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
345329
where
346330
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
347331
{
348-
map!(input, be_u64, |x| x as i64)
332+
be_u64.map(|x| x as i64).parse(input)
349333
}
350334

351335
/// Recognizes a big endian signed 16 bytes integer.
@@ -368,7 +352,7 @@ pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
368352
where
369353
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
370354
{
371-
map!(input, be_u128, |x| x as i128)
355+
be_u128.map(|x| x as i128).parse(input)
372356
}
373357

374358
/// Recognizes an unsigned 1 byte integer.
@@ -586,7 +570,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
586570
where
587571
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
588572
{
589-
map!(input, be_u8, |x| x as i8)
573+
be_u8.map(|x| x as i8).parse(input)
590574
}
591575

592576
/// Recognizes a little endian signed 2 bytes integer.
@@ -609,7 +593,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
609593
where
610594
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
611595
{
612-
map!(input, le_u16, |x| x as i16)
596+
le_u16.map(|x| x as i16).parse(input)
613597
}
614598

615599
/// Recognizes a little endian signed 3 bytes integer.
@@ -633,11 +617,15 @@ where
633617
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
634618
{
635619
// Same as the unsigned version but we need to sign-extend manually here
636-
map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
637-
(x | 0xff_00_00_00) as i32
638-
} else {
639-
x as i32
640-
})
620+
le_u24
621+
.map(|x| {
622+
if x & 0x80_00_00 != 0 {
623+
(x | 0xff_00_00_00) as i32
624+
} else {
625+
x as i32
626+
}
627+
})
628+
.parse(input)
641629
}
642630

643631
/// Recognizes a little endian signed 4 bytes integer.
@@ -660,7 +648,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
660648
where
661649
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
662650
{
663-
map!(input, le_u32, |x| x as i32)
651+
le_u32.map(|x| x as i32).parse(input)
664652
}
665653

666654
/// Recognizes a little endian signed 8 bytes integer.
@@ -683,7 +671,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
683671
where
684672
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
685673
{
686-
map!(input, le_u64, |x| x as i64)
674+
le_u64.map(|x| x as i64).parse(input)
687675
}
688676

689677
/// Recognizes a little endian signed 16 bytes integer.
@@ -706,7 +694,7 @@ pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
706694
where
707695
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
708696
{
709-
map!(input, le_u128, |x| x as i128)
697+
le_u128.map(|x| x as i128).parse(input)
710698
}
711699

712700
/// Recognizes an unsigned 1 byte integer
@@ -957,7 +945,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
957945
where
958946
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
959947
{
960-
map!(i, u8, |x| x as i8)
948+
u8.map(|x| x as i8).parse(i)
961949
}
962950

963951
/// Recognizes a signed 2 byte integer

src/number/streaming.rs

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,6 @@ use crate::traits::{
1212
AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice,
1313
};
1414

15-
#[doc(hidden)]
16-
macro_rules! map(
17-
// Internal parser, do not use directly
18-
(__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
19-
$crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i)
20-
);
21-
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
22-
map!(__impl $i, $submac!($($args)*), $g)
23-
);
24-
($i:expr, $f:expr, $g:expr) => (
25-
map!(__impl $i, call!($f), $g)
26-
);
27-
);
28-
29-
#[doc(hidden)]
30-
macro_rules! call (
31-
($i:expr, $fun:expr) => ( $fun( $i ) );
32-
($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) );
33-
);
34-
3515
/// Recognizes an unsigned 1 byte integer.
3616
///
3717
/// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data.
@@ -242,7 +222,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
242222
where
243223
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
244224
{
245-
map!(input, be_u8, |x| x as i8)
225+
be_u8.map(|x| x as i8).parse(input)
246226
}
247227

248228
/// Recognizes a big endian signed 2 bytes integer.
@@ -262,7 +242,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
262242
where
263243
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
264244
{
265-
map!(input, be_u16, |x| x as i16)
245+
be_u16.map(|x| x as i16).parse(input)
266246
}
267247

268248
/// Recognizes a big endian signed 3 bytes integer.
@@ -283,11 +263,15 @@ where
283263
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
284264
{
285265
// Same as the unsigned version but we need to sign-extend manually here
286-
map!(input, be_u24, |x| if x & 0x80_00_00 != 0 {
287-
(x | 0xff_00_00_00) as i32
288-
} else {
289-
x as i32
290-
})
266+
be_u24
267+
.map(|x| {
268+
if x & 0x80_00_00 != 0 {
269+
(x | 0xff_00_00_00) as i32
270+
} else {
271+
x as i32
272+
}
273+
})
274+
.parse(input)
291275
}
292276

293277
/// Recognizes a big endian signed 4 bytes integer.
@@ -307,7 +291,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
307291
where
308292
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
309293
{
310-
map!(input, be_u32, |x| x as i32)
294+
be_u32.map(|x| x as i32).parse(input)
311295
}
312296

313297
/// Recognizes a big endian signed 8 bytes integer.
@@ -328,7 +312,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
328312
where
329313
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
330314
{
331-
map!(input, be_u64, |x| x as i64)
315+
be_u64.map(|x| x as i64).parse(input)
332316
}
333317

334318
/// Recognizes a big endian signed 16 bytes integer.
@@ -348,7 +332,7 @@ pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
348332
where
349333
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
350334
{
351-
map!(input, be_u128, |x| x as i128)
335+
be_u128.map(|x| x as i128).parse(input)
352336
}
353337

354338
/// Recognizes an unsigned 1 byte integer.
@@ -560,7 +544,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E>
560544
where
561545
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
562546
{
563-
map!(input, le_u8, |x| x as i8)
547+
le_u8.map(|x| x as i8).parse(input)
564548
}
565549

566550
/// Recognizes a little endian signed 2 bytes integer.
@@ -583,7 +567,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E>
583567
where
584568
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
585569
{
586-
map!(input, le_u16, |x| x as i16)
570+
le_u16.map(|x| x as i16).parse(input)
587571
}
588572

589573
/// Recognizes a little endian signed 3 bytes integer.
@@ -607,11 +591,15 @@ where
607591
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
608592
{
609593
// Same as the unsigned version but we need to sign-extend manually here
610-
map!(input, le_u24, |x| if x & 0x80_00_00 != 0 {
611-
(x | 0xff_00_00_00) as i32
612-
} else {
613-
x as i32
614-
})
594+
le_u24
595+
.map(|x| {
596+
if x & 0x80_00_00 != 0 {
597+
(x | 0xff_00_00_00) as i32
598+
} else {
599+
x as i32
600+
}
601+
})
602+
.parse(input)
615603
}
616604

617605
/// Recognizes a little endian signed 4 bytes integer.
@@ -634,7 +622,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E>
634622
where
635623
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
636624
{
637-
map!(input, le_u32, |x| x as i32)
625+
le_u32.map(|x| x as i32).parse(input)
638626
}
639627

640628
/// Recognizes a little endian signed 8 bytes integer.
@@ -657,7 +645,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E>
657645
where
658646
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
659647
{
660-
map!(input, le_u64, |x| x as i64)
648+
le_u64.map(|x| x as i64).parse(input)
661649
}
662650

663651
/// Recognizes a little endian signed 16 bytes integer.
@@ -680,7 +668,7 @@ pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E>
680668
where
681669
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
682670
{
683-
map!(input, le_u128, |x| x as i128)
671+
le_u128.map(|x| x as i128).parse(input)
684672
}
685673

686674
/// Recognizes an unsigned 1 byte integer
@@ -931,7 +919,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E>
931919
where
932920
I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength,
933921
{
934-
map!(i, u8, |x| x as i8)
922+
u8.map(|x| x as i8).parse(i)
935923
}
936924

937925
/// Recognizes a signed 2 byte integer

0 commit comments

Comments
 (0)