Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathBuf does not have is_empty() #30259

Closed
dhardy opened this issue Dec 7, 2015 · 6 comments
Closed

PathBuf does not have is_empty() #30259

dhardy opened this issue Dec 7, 2015 · 6 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dhardy
Copy link
Contributor

dhardy commented Dec 7, 2015

It is possible to create an empty PathBuf:

let p = PathBuf::new();

— yet PathBuf has no is_empty() function (nor, apparently, do Path or OsStr or OsString).

This seems inconsistent.

Of course, there are several ways around this (p == PathBuf::new(), p.to_str().map_or(true, |s| s.is_empty()), wrapping with Option), but having a simple way to check this would be nice.

@frewsxcv
Copy link
Member

Implemented in #31877.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 25, 2016
Original issue requesting this feature:
rust-lang#30259

Originally implemented in rust-lang#30623
but that pull request when stale.

It was rebased in rust-lang#31231, but the
`Path` changes got lost as the focus shifted towards `OsString` and
`OsStr`.

An RFC (rust-lang/rfcs#1497) was briefly
opened, since I didn't know if this functionality needed an RFC, but
@alexcrichton clarified in the RFC issue I linked that this is not the
case.
@frewsxcv
Copy link
Member

frewsxcv commented Mar 2, 2016

Now that #31608 landed, getting the length and emptiness is pretty easy:

let _ = some_path.as_os_str().len();
let _ = some_path.as_os_str().is_empty();

Does anyone think it's still worth it to add the len and is_empty methods on Path?

@dhardy
Copy link
Contributor Author

dhardy commented Mar 2, 2016

I don't see why you'd want len() but is_empty() would be useful.

@alexcrichton
Copy link
Member

Closing due to the reasons outlined in this comment

@dhardy
Copy link
Contributor Author

dhardy commented Mar 3, 2016

@alexcrichton My use-case was completely different: using path == PathBuf::new() as a synonym for None. Possibly I should just wrap with Option even though technically it's more abstraction than needed.

@alexcrichton
Copy link
Member

Yeah for now you probably want to take a look at .as_os_str() if you want to test a literally empty buffer, and otherwise None would probably be best for "this hasn't been initialized"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants