Rust: Tracking issue for PathBuf capacity methods

Created on 6 Feb 2019  路  17Comments  路  Source: rust-lang/rust

B-unstable C-tracking-issue T-libs disposition-merge finished-final-comment-period

All 17 comments

Happy to take this on as a first contribution to rust.

Great! I'd be happy to help you get started, just let me know if you want mentoring/instructions at any level!

@Mark-Simulacrum are you able to define a list of the methods that need to be implemented as part of this PR?

I think all of these will essentially call the underlying functions on OsString.

  • [ ] capacity
  • [ ] with_capacity
  • [ ] clear
  • [ ] reserve
  • [ ] reserve_exact
  • [ ] shrink_to_fit
  • [ ] shrink_to -- this one is more of a maybe, since it's unstable on OsString. We can reuse the same tracking issue for this.

We'll probably want to add all of these under the same feature gate.

@Mark-Simulacrum thanks for that. I have the implementation drafted locally. I'm having some difficulty however in running the tests for stdlib - even a cargo check is producing errors not related to my changes. Is there any documentation I've missed for best practices on compiling / working on stdlib?

You'll want to use x.py; for your scenario I believe x.py test --stage 0 src/libstd and/or x.py check src/libstd are the commands you want. I'm not sure where the most current documentation is.

This page on rustc guide describes how to use x.py.

Triage: since #58539 has been merged, can this be closed?

No, this is now the tracking issue for the stabilization of those APIs.

Reviewing this since then, I think it may be worth removing these APIs and replacing them with something like AsRef<OsString> for PathBuf and AsMut. These aren't really commonly used so hiding them as such seems reasonable and is less heavy.

I'd love to see these stabilized. I have a tool that manipulates lots of paths, so I'd like to avoid needless reallocations.

  • I generate lots of temporary paths in a loop. PathBuf.clear() + PathBuf.push() would work nicely to reuse the buffer.

  • I need to concatenate several components. I know their length, so I could use PathBuf::with_capacity()

  • I want to store lots of paths for later. Box<Path> is a bit smaller than PathBuf, but if I can't reserve exact capacity, into() will reallocate.

@rfcbot merge

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @Amanieu
  • [ ] @KodrAus
  • [x] @SimonSapin
  • [x] @dtolnay
  • [x] @sfackler
  • [ ] @withoutboats

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot reviewed
assuming we're only stabilizing capacity + with_capacity + clear + reserve + reserve_exact + shrink_to_fit; and shrink_to is being moved to https://github.com/rust-lang/rust/issues/56431 instead.

:bell: This is now entering its final comment period, as per the review above. :bell:

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

I've posted a stabilization PR in #71328.

Was this page helpful?
0 / 5 - 0 ratings