4 ms·
I mean, you're a big grown-up language with generic programming, why can't you: https://doc.rust-lang.org/std/primitive.str.html#method.trim_end_matches https:
by tialaramex 2y ago
I mean, you're a big grown-up language with generic programming, why can't you:
https://doc.rust-lang.org/std/primitive.str.html#method.trim_end_matches https://doc.rust-lang.org/std/primitive.str.html#method.trim...
C++ can't manage to do this because it doesn't give its primitive types methods, it doesn't have a sensible way to talk about methods on types, and it always coerces to function pointers...
assert_eq!("123foo1bar123".trim_end_matches(char::is_numeric), "123foo1bar");
But it's pretty easy to at least do this:
assert_eq!("11foo1bar11".trim_end_matches('1'), "11foo1bar");
(Yes Rust does provide one that always trims off trailing whitespace, but that requires that you know, as Rust does, what the encoding is)