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

Tracking Issue for PathBuf::add_extension and Path::with_added_extension #127292

Open
2 of 4 tasks
tisonkun opened this issue Jul 3, 2024 · 16 comments
Open
2 of 4 tasks
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Comments

@tisonkun
Copy link
Contributor

tisonkun commented Jul 3, 2024

Feature gate: #![feature(path_add_extension)]

This is a tracking issue for

  • PathBuf::add_extension
  • Path::with_added_extension

Public API

impl PathBuf {
    pub fn add_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool { ... )
}

impl Path {
    pub fn with_added_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf { ... }
}

Steps / History

Unresolved Questions

None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html
@tisonkun tisonkun added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Jul 3, 2024
@tisonkun tisonkun changed the title Tracking Issue for PathBuf::add_extension and Path::with_added_extension Tracking Issue for PathBuf::add_extension and Path::with_extra_extension Jul 3, 2024
@tisonkun tisonkun changed the title Tracking Issue for PathBuf::add_extension and Path::with_extra_extension Tracking Issue for PathBuf::add_extension and Path:: with_added_extension Jul 4, 2024
@tisonkun tisonkun changed the title Tracking Issue for PathBuf::add_extension and Path:: with_added_extension Tracking Issue for PathBuf::add_extension and Path::with_added_extension Jul 4, 2024
@MordechaiHadad
Copy link

This would be really awesome honestly, just encountered an issue where this would have made my life easier.

@dilawar
Copy link

dilawar commented Sep 22, 2024

Hoping this becomes available in stable soon. Such a nice QoL api.

@anatawa12
Copy link
Contributor

This new API is awesome!

But I think It would be better to rename (deprecate old and add new name) existing API with_extension with with_replaced_extension and set_extension with replace_extension along with this feature.
I feel existing function with_extension and set_extension is confusing if it will replace or append extension.

Actually I mistakenly used with_extension as with_added_extension and we can see some such case in rust form like this.

@dvdsk
Copy link
Contributor

dvdsk commented Dec 22, 2024

But I think It would be better to rename (deprecate old and add new name) existing API with_extension with with_replaced_extension and set_extension with replace_extension along with this feature.

I agree with the rename however we can only do that with a new edition (since with_extension is stable) right? And that might take a few more years. That should not block the stabilization of the added API.

@anatawa12
Copy link
Contributor

I don't think edition change is required since we don't have to actually rename the function.
We can introduce with_replaced_extension in some version, and deprecate with_extension in following or later version.

I think there are some cases that deprecating without edition change like deprecate _ms functions with Duration parameter variants.

@Amanieu Amanieu added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 7, 2025
@joshtriplett joshtriplett added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC and removed C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Jan 7, 2025
@joshtriplett
Copy link
Member

Starting an FCP to stabilize this:

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Jan 7, 2025

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

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 rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jan 7, 2025
@rfcbot
Copy link

rfcbot commented Jan 7, 2025

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

@tgross35
Copy link
Contributor

tgross35 commented Jan 7, 2025

Some late bikeshed: the name with_added_extension feels very unnatural, what about the names push_extension and join_extension? This nicely mirrors what we have for path components:

impl Path {
    pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf;
    pub fn join_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
}

impl PathBuf {
    pub fn push<P: AsRef<Path>>(&mut self, path: P);
    pub fn push_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool;
}

@tisonkun
Copy link
Contributor Author

tisonkun commented Jan 9, 2025

FYI the naming discussion also happened in the ACP period - rust-lang/libs-team#368 (comment)

@Amanieu Amanieu added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jan 10, 2025
@Amanieu
Copy link
Member

Amanieu commented Jan 14, 2025

We discussed this in the libs-api meeting. There was a slight preference towards keeping the "add"-based names since it is consistent with set_extension and with_extension.

@tbu-
Copy link
Contributor

tbu- commented Jan 16, 2025

This API currently seems to have the same issue as Path::set_extension had before introducing a panic in #125070.

This API should probably panic as well if the passed extension contains a path separator.

@tbu-
Copy link
Contributor

tbu- commented Jan 16, 2025

Additional, but much less important point: The add_extension API returns a boolean which is likely not checked at call site to communicate its success in adding the extension. I think it'd be a lot better if it returned a Result which would make the user think about what to do if the file extension could not be set.

This is exemplified in the with_added_extension API which promptly forgets to check the result of add_extension and currently also has no way to return that result to the user.

@T0mstone
Copy link

I think it'd be a lot better if it returned a Result which would make the user think about what to do if the file extension could not be set.

Alternatively, the function could just be annotated with #[must_use].

@tisonkun
Copy link
Contributor Author

This API currently seems to have the same issue as Path::set_extension had before introducing a panic in #125070.

This sounds reasonable to keep the manner in sync. As you're the author of #125070, would you submit a PR to apply the same for add_extension? Otherwise, I can submit one.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jan 17, 2025
@rfcbot
Copy link

rfcbot commented Jan 17, 2025

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.

This will be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

No branches or pull requests