Skip to content

Commit 3d9196b

Browse files
o-x-e-yeldruin
authored andcommitted
Allow singular lb in from_str()
Parsing mass currently breaks on something like `1 lb` which seems like a bit of an oversight, this should fix that
1 parent 0c10b3e commit 3d9196b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mass.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl FromStr for Mass {
280280
"dwt" => Mass::from_pennyweights(float_val.parse::<f64>()?),
281281
"oz" => Mass::from_ounces(float_val.parse::<f64>()?),
282282
"st" => Mass::from_stones(float_val.parse::<f64>()?),
283-
"lbs" => Mass::from_pounds(float_val.parse::<f64>()?),
283+
"lb" | "lbs" => Mass::from_pounds(float_val.parse::<f64>()?),
284284
_ => Mass::from_grams(float_val.parse::<f64>()?),
285285
},
286286
);
@@ -602,6 +602,7 @@ mod test {
602602
fn pounds_from_string() {
603603
assert_almost_eq(123.0, Mass::from_str("123lbs").unwrap().as_pounds());
604604
assert_almost_eq(123.0, Mass::from_str("123 lbs").unwrap().as_pounds());
605+
assert_almost_eq(123.0, Mass::from_str("123 lb").unwrap().as_pounds());
605606
}
606607

607608
#[test]

0 commit comments

Comments
 (0)