24 ms·
It took some coaching to get it to use the terse style I prefer, but here’s what 3.5 came up with in a conversation where I first asked about Rust’s support for
by textninja 4y ago
It took some coaching to get it to use the terse style I prefer, but here’s what 3.5 came up with in a conversation where I first asked about Rust’s support for regular expressions:
use regex::Regex;
fn strip_suffix_digits(s: &str) -> &str {
let re = Regex::new(r"_\d+$").unwrap();
re.replace(s, "").as_ref()
}
As someone who does not program in Rust I find that quite readable, though I haven’t run it and can’t comment on how it compares outside of LOC. It does depend on the regex crate though.
- lamontcg 4y agoYeah I got basically the same sort of result out of it by asking for a Regexp, much shorter.