Crazy I know but I have a path in a String and I want to knock the filename off the end of it.
In python path[:path.rfind("/")] would do the job in a jiffy. What would be a vaguely eligant way to do the same in Rust?
Crazy I know but I have a path in a String and I want to knock the filename off the end of it.
In python path[:path.rfind("/")] would do the job in a jiffy. What would be a vaguely eligant way to do the same in Rust?
Ah ha, the Rust equivilent of 'rfind' is 'rfind'. Ironic I didn't find that earlier!
This seems pleasingly succinct:
let (head, _) = path.split_at(path.rfind("/").unwrap());
Well done Rust.
Path in std::path - Rust might be more appropriate in this case I think
Even slicker - nice.