Skip to content

Commit

Permalink
Trim whitespace before parsing primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
miam-miam committed Dec 7, 2023
1 parent 1d52591 commit 5d9e469
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lending_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! impl_parse {
$(
impl<'a> Parse<'a> for $Ty {
fn from_str(s: &'a str) -> Result<Self, ParseError> {
<Self as FromStr>::from_str(&s).map_err(|e| e.into())
<Self as FromStr>::from_str(s.trim()).map_err(|e| e.into())
}
}
)+
Expand Down
8 changes: 8 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ mod common {
parse!("yummy gummy-bear", "{}")
);
}

#[test]
fn parse_trim() {
assert_eq!(
(false, 2_u8, 3_i32, 5_f64),
parse!(" false , 2 , 3 , 5.0 ", "{},{},{},{}")
)
}
}

0 comments on commit 5d9e469

Please sign in to comment.