Suggestion to let PathBuf::Pop return popped value?

I try to detect if a revision control tool is used for my application by inspecting the presence of a hidden directory name. However, I would also like to inspect if the user is not reading or writing in that hidden revision control directory itself, as this will be dangerous.

Using a pop function on PathBuf looks like what I needed, but to my surprise it doesn't return the popped value, see: rename std::path::PathBuf::pop · Issue #23731 · rust-lang/rust · GitHub (I added the most recent comment).

Any suggestions? Shall I re-open the issue or write my own function for this?

This is part of the standard library, and isn't entirely backwards compatible, which makes it difficult to change. Deprecation or a breaking change would cause code churn, and Rust prefers to avoid that.

From memory management perspective it may be doable to return a reference to the popped part, because lifetimes can keep it alive and prevent getting overwritten, despite being past the end of buffer of the PathBuf. I'm not sure how Miri would like that tho.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.