let mut parts = l.split(&['@', ',', ':', 'x'][..])
.flat_map(|s| s.trim().parse::<i32>().ok());
let x = parts.next().expect("x as i32");
let y = parts.next().expect("y as i32");
let w = parts.next().expect("width as i32");
let h = parts.next().expect("height as i32");Why not? cargo makes it extremely easy to add new crates. The hardest part is figuring out what dependency you want, but once you know what it is, adding it is really easy.
$ cargo search regex
regex = "1.1.0" # An implementation of regular expressions for Rust. This implementation uses finite automata and gua…
regex-automata = "0.1.5" # Automata construction and matching using regular expressions.
…"The pattern can be a &str, char, or a closure that determines the split."
But in your case it is an array of chars and it splits for each of them. I don't see this documented at all.
[0] https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html...
It’s possible that it used to be only those types, but was expanded. We should fix this!
The operator for this is for eg l[1..10]. It can also happen automatically.
&str is the same type as &[char] - just a renaming.
Still learning Rust myself, apologies if this leads you astray. Just do some reading on slices.
https://doc.rust-lang.org/book/ch04-03-slices.html#string-sl...