|
|
|
|
|
by general_pizza
2687 days ago
|
|
I also thought regex seemed overkill and didn't feel like adding an extra crate to my Cargo.toml. Luckily for the days I attempted I was able to get by on just the split method for str's[0] which was nice and concise. So for your regex example you could also do: // #1 @ 916,616: 21x29
let parts: Vec<&str> = l.split(['@', ',', ':', 'x'].as_ref()).collect();
let x = parts[1].trim().parse::<i32>().expect("x as i32");
let y = parts[2].trim().parse::<i32>().expect("y as i32");
let w = parts[3].trim().parse::<i32>().expect("width as i32");
let h = parts[4].trim().parse::<i32>().expect("height as i32");
[0] https://doc.rust-lang.org/std/primitive.str.html#method.spli... |
|