I don't understand how Rust concatenates file paths. Why doesn't this work:
fn main() {
let root = std::path::Path::new("resources/");
let uri = std::path::Path::new("/js/main.js");
let path = root.join(uri);
assert_eq!(path.to_str(), Some("resources/js/main.js"));
}
fails with:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Some("/js/main.js")`,
right: `Some("resources/js/main.js")`', src/main.rs:5:5
I see in the docs that "pushing an absolute path replaces the existing path", but this seems like a terrible idea that will catch a lot of people.
In that case, how do I safely strip the absolute path, or make it relative?