hg-core: make use of `strip_suffix` now that we're using Rust 1.45+
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 14 Nov 2022 15:43:05 +0100
changeset 49753 4d729a98673d
parent 49752 ec399ddf6764
child 49754 a5447a4a8c5d
hg-core: make use of `strip_suffix` now that we're using Rust 1.45+
rust/hg-core/src/config/values.rs
--- a/rust/hg-core/src/config/values.rs	Mon Nov 14 15:34:51 2022 +0100
+++ b/rust/hg-core/src/config/values.rs	Mon Nov 14 15:43:05 2022 +0100
@@ -30,10 +30,8 @@
         ("b", 1 << 0), // Needs to be last
     ];
     for &(unit, multiplier) in UNITS {
-        // TODO: use `value.strip_suffix(unit)` when we require Rust 1.45+
-        if value.ends_with(unit) {
-            let value_before_unit = &value[..value.len() - unit.len()];
-            let float: f64 = value_before_unit.trim().parse().ok()?;
+        if let Some(value) = value.strip_suffix(unit) {
+            let float: f64 = value.trim().parse().ok()?;
             if float >= 0.0 {
                 return Some((float * multiplier as f64).round() as u64);
             } else {