Closed
Description
Hi,
not a huge problem but I just stumbled over this while bumping "regex = 0.1" to "0.2:
I was using a lot of this (IRC parsing code):
let caps = re_priv.captures(line).unwrap();
let sender = caps.at(1).unwrap()
let msg = caps.at(2).unwrap_or("");
Now it looks like this (thanks #rust for the help)
let caps = re_priv.captures(line).unwrap();
let sender = caps.get(1).unwrap().as_str();
let msg = caps.get(2).as_ref().map(regex::Match::as_str).unwrap_or("");
// alternative:
let msg = caps.get(2).map_or("", |m| m.as_str());
So my reasoning is now this:
- In this use case I don't care about much error handling
- this is inherently text, so no match/empty string can make sense
- both of the two 0.2 versions are either verbose or not easily guessable (at least to a beginner)
So I don't really want to complain, but I think the syntax (for this use case) got less usable and more verbose, but I don't know if it's worth fixing or if .at() had any other problems.