Skip to content

Commit 808c25b

Browse files
committed
Cleaner way to ignore return value.
1 parent 90c894b commit 808c25b

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn expression(input: &[u8]) -> PResult<&str> {
1414
recognize(context(
1515
"Expected rust expression",
1616
(
17-
map_res(alt((tag("&"), tag("*"), tag(""))), input_to_str),
17+
alt((tag("&"), tag("*"), tag(""))),
1818
alt((
1919
rust_name,
2020
map_res(digit1, input_to_str),

src/spacelike.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use crate::parseresult::PResult;
22
use nom::branch::alt;
33
use nom::bytes::complete::{is_not, tag};
44
use nom::character::complete::{multispace1, none_of};
5-
use nom::combinator::{map, value};
5+
use nom::combinator::value;
66
use nom::multi::many0;
77
use nom::sequence::preceded;
88
use nom::Parser as _;
99

1010
pub fn spacelike(input: &[u8]) -> PResult<()> {
11-
map(many0(alt((comment, map(multispace1, |_| ())))), |_| ()).parse(input)
11+
value((), many0(alt((comment, value((), multispace1))))).parse(input)
1212
}
1313

1414
pub fn comment(input: &[u8]) -> PResult<()> {

src/template.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use nom::branch::alt;
77
use nom::bytes::complete::is_not;
88
use nom::bytes::complete::tag;
99
use nom::character::complete::{char, multispace0};
10-
use nom::combinator::{map, map_res, opt, recognize};
10+
use nom::combinator::{map, map_res, opt, recognize, value};
1111
use nom::error::context;
1212
use nom::multi::{many0, many_till, separated_list0, separated_list1};
1313
use nom::sequence::{delimited, preceded, terminated};
@@ -152,7 +152,8 @@ fn formal_argument(input: &[u8]) -> PResult<&str> {
152152
}
153153

154154
fn type_expression(input: &[u8]) -> PResult<()> {
155-
map(
155+
value(
156+
(),
156157
(
157158
alt((tag("&"), tag(""))),
158159
opt(lifetime),
@@ -164,40 +165,37 @@ fn type_expression(input: &[u8]) -> PResult<()> {
164165
context(
165166
"Expected rust type expression",
166167
alt((
167-
map(rust_name, |_| ()),
168-
map(
169-
delimited(tag("["), type_expression, tag("]")),
170-
|_| (),
171-
),
172-
map(
173-
delimited(tag("("), comma_type_expressions, tag(")")),
174-
|_| (),
168+
value((), rust_name),
169+
delimited(tag("["), value((), type_expression), tag("]")),
170+
delimited(
171+
tag("("),
172+
value((), comma_type_expressions),
173+
tag(")"),
175174
),
176175
)),
177176
),
178177
opt(delimited(tag("<"), comma_type_expressions, tag(">"))),
179178
),
180-
|_| (),
181179
)
182180
.parse(input)
183181
}
184182

185183
pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
186-
map(
184+
value(
185+
(),
187186
terminated(
188187
separated_list0(
189188
preceded(tag(","), multispace0),
190189
alt((type_expression, lifetime)),
191190
),
192191
opt(preceded(tag(","), multispace0)),
193192
),
194-
|_| (),
195193
)
196194
.parse(input)
197195
}
198196

199197
fn lifetime(input: &[u8]) -> PResult<()> {
200-
map(delimited(spacelike, tag("'"), rust_name), |_| ()).parse(input)
198+
delimited(spacelike, value((), tag("'")), rust_name).parse(input)
201199
}
202200

203201
#[cfg(test)]

0 commit comments

Comments
 (0)