I am trying to extract the containing folder of a file in Rust. Is there any way to go from a String to getting the containing folder? For example, the following code works, however it is messy:
let path = "/path/to/file.txt";
let mut path_arr: Vec<&str> = path.split('/').collect();
path_arr.pop();
let new_string = path_arr.join("/");
assert_eq!("/path/to", new_string);