-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Description
use std::path::Path;
fn main() {
println!("{:?}", Path::new("/").parent()); // None
println!("{:?}", Path::new(".").parent()); // Some("")
println!("{:?}", Path::new("foo").parent()); // Some("")
}
The latter two cases feel weird to me. Some("")
by itself is kind of a contradiction, on the one hand saying "yes there is a parent" and on the other hand returning an invalid path that really means "no there isn't actually a parent." We've also tried to avoid creating empty path components in other cases, like the double-slash case Path::new("a//b").parent()
, which returns Some("a")
rather than Some("")
.
For consistency with /
, it probably makes sense to have the parent of .
be None
. For foo
I could imagine going either of two ways, either Some(".")
or None
. If folks agree that one of those options would be nice in theory, then I guess the second question is whether a behavior change here would break backwards compatibility too much to consider doing it. Would it make sense for me to put together a PR and then ask for a Crater run or something like that?