Just a small piece of ergonomics feedback: On the unofficial Rust Discord server, a beginner posted this snippet today:
enum TokenType {
Symbol(usize, usize),
// ...
}
for token in tokens.iter() {
let out = match token {
TokenType::Name(start, end) => {
println!("Name: {}", &contentstr[start..end]);
},
// ...
_ => println!("Unknown token.")
};
}
This fails with the following error message:
the type `str` cannot be indexed by `std::ops::Range<&usize>`
The solution here is to write match *token, but this was rather unintuitive to them and the error message didn’t point them at the right location. (I got somewhat confused by the message as well and initially suggested the sub-par solution &contentstr[*start..*end].)