Skip to content

Commit e70fd6b

Browse files
refactor: add strip_suffix_with_value helper
1 parent 05b3d51 commit e70fd6b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

moz-webgpu-cts/src/wpt/path.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ impl SpecType {
7878

7979
pub fn from_base_name(base_name: &str) -> Option<(Self, &str)> {
8080
Self::iter().find_map(|variant| {
81-
base_name
82-
.strip_suffix(variant.file_extension())
83-
.map(|some| (variant, some))
81+
strip_suffix_with_value(base_name, variant.file_extension(), variant)
8482
})
8583
}
8684

@@ -432,6 +430,10 @@ impl From<ServoRootDir> for RootDir {
432430
}
433431
}
434432

433+
fn strip_suffix_with_value<'a, T>(s: &'a str, suffix: &str, t: T) -> Option<(T, &'a str)> {
434+
s.strip_suffix(suffix).map(|some| (t, some))
435+
}
436+
435437
#[test]
436438
fn parse_test_entry_path() {
437439
assert_eq!(

0 commit comments

Comments
 (0)