Skip to content

Commit e2b717b

Browse files
Copilottomtau
andcommitted
Use is_no_match() helper for better maintainability
Address code review feedback to use the is_no_match() helper method instead of pattern matching both NoMatch variants explicitly. Co-authored-by: tomtau <[email protected]>
1 parent 3c6f314 commit e2b717b

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

derive/src/from_pest/field.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ impl ConversionStrategy {
9898
// Try to parse using FromPest first
9999
match ::from_pest::FromPest::from_pest(inner) {
100100
Ok(value) => value,
101-
Err(::from_pest::ConversionError::NoMatch) |
102-
Err(::from_pest::ConversionError::NoMatchWithInfo { .. }) => #default_expr,
101+
Err(ref e) if e.is_no_match() => #default_expr,
103102
Err(e) => return Err(e),
104103
}
105104
}}

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'pest, Rule: RuleType, T: FromPest<'pest, Rule = Rule>> FromPest<'pest> for
141141
type FatalError = T::FatalError;
142142
fn from_pest(pest: &mut Pairs<'pest, Rule>) -> Result<Self, ConversionError<T::FatalError>> {
143143
match T::from_pest(pest) {
144-
Err(ConversionError::NoMatch) | Err(ConversionError::NoMatchWithInfo { .. }) => Ok(None),
144+
Err(ref e) if e.is_no_match() => Ok(None),
145145
result => result.map(Some),
146146
}
147147
}
@@ -156,9 +156,7 @@ impl<'pest, Rule: RuleType, T: FromPest<'pest, Rule = Rule>> FromPest<'pest> for
156156
loop {
157157
match T::from_pest(pest) {
158158
Ok(t) => acc.push(t),
159-
Err(ConversionError::NoMatch) | Err(ConversionError::NoMatchWithInfo { .. }) => {
160-
break
161-
}
159+
Err(ref e) if e.is_no_match() => break,
162160
Err(error) => return Err(error),
163161
}
164162
}

0 commit comments

Comments
 (0)