From e70fd6bf191b1ed23e4c572b3923a6001a1b5ec1 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 21 Jun 2024 10:50:33 -0400 Subject: [PATCH] refactor: add `strip_suffix_with_value` helper --- moz-webgpu-cts/src/wpt/path.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/moz-webgpu-cts/src/wpt/path.rs b/moz-webgpu-cts/src/wpt/path.rs index 7186949..7a36c78 100644 --- a/moz-webgpu-cts/src/wpt/path.rs +++ b/moz-webgpu-cts/src/wpt/path.rs @@ -78,9 +78,7 @@ impl SpecType { pub fn from_base_name(base_name: &str) -> Option<(Self, &str)> { Self::iter().find_map(|variant| { - base_name - .strip_suffix(variant.file_extension()) - .map(|some| (variant, some)) + strip_suffix_with_value(base_name, variant.file_extension(), variant) }) } @@ -432,6 +430,10 @@ impl From for RootDir { } } +fn strip_suffix_with_value<'a, T>(s: &'a str, suffix: &str, t: T) -> Option<(T, &'a str)> { + s.strip_suffix(suffix).map(|some| (t, some)) +} + #[test] fn parse_test_entry_path() { assert_eq!(