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 CStr::is_empty #102444

Closed
2 of 3 tasks
jmillikin opened this issue Sep 28, 2022 · 13 comments · Fixed by #111043
Closed
2 of 3 tasks

Tracking Issue for CStr::is_empty #102444

jmillikin opened this issue Sep 28, 2022 · 13 comments · Fixed by #111043
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jmillikin
Copy link
Contributor

jmillikin commented Sep 28, 2022

Feature gate: #![feature(cstr_is_empty)]

This is a tracking issue for adding an is_empty() method to core::ffi::CStr.

ACP: rust-lang/libs-team#106

Public API

// core::ffi

impl CStr {
	pub const fn is_empty(&self) -> bool;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@jmillikin jmillikin added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 28, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 11, 2022
…mulacrum

Add `is_empty()` method to `core::ffi::CStr`.

ACP: rust-lang/libs-team#106

Tracking issue: rust-lang#102444
RalfJung pushed a commit to RalfJung/miri that referenced this issue Oct 12, 2022
@jmillikin
Copy link
Contributor Author

Gentle ping for @rust-lang/libs-api -- would it be possible to start the FCP now? I don't think there's much API surface to review.

thomcc pushed a commit to tcdi/postgrestd that referenced this issue Feb 10, 2023
@jmillikin
Copy link
Contributor Author

(pinging someone from the libs team, per instructions at https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html)

@cuviper I'd like to start the FCP for this feature. The new method has been in nightly since v1.66, and it'd be nice to have it in stable.

@jmillikin
Copy link
Contributor Author

jmillikin commented May 1, 2023

Timed out waiting for someone to start the FCP -- since there's not much to discuss regarding the API, I sent in PR #111043 to stabilize.

@BurntSushi
Copy link
Member

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 2, 2023

Team member @BurntSushi 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. labels May 2, 2023
@BurntSushi
Copy link
Member

@rust-lang/libs-api This issue is for stabilizing CStr::is_empty, which seems sensible. It returns true in precisely the cases where CStr::to_bytes().is_empty() returns true. One odd thing here is that there is no CStr::len method, but that can always be added in the future.

@jmillikin
Copy link
Contributor Author

Thank you for starting the FCP!

One odd thing here is that there is no CStr::len method, but that can always be added in the future.

My understanding from the CStr docs is that a future version is expected to remove the construction-time length check, so new() would become cheap and len() (if it existed) would be expensive (basically C's strlen()).

Having a len() that iterates through the entire value seems surprising enough that it's worth its own ACP, and I don't feel I have enough context to be the person to write it.

@BurntSushi
Copy link
Member

@jmillikin Yes that makes sense. I just mean that it is somewhat odd from an API perspective. Usually if there's an is_empty and its a collection, then there's also a len method. And vice versa. I raise it as something that I find a little odd, but not a blocker for moving forward.

@rfcbot rfcbot added 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 May 2, 2023
@rfcbot
Copy link

rfcbot commented May 2, 2023

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

@madsmtm
Copy link
Contributor

madsmtm commented May 5, 2023

Having a len() that iterates through the entire value seems surprising enough that it's worth its own ACP

But is this not also the case for is_empty? In the future, is_empty would iterate through the entire value, which I think is just as surprising.

@zopsicle
Copy link
Contributor

zopsicle commented May 5, 2023

is_empty just checks the first byte. No iteration necessary. That's why it's worth having in addition to len, as len == 0 would be linear time.

@madsmtm
Copy link
Contributor

madsmtm commented May 5, 2023

is_empty just checks the first byte. No iteration necessary. That's why it's worth having in addition to len, as len == 0 would be linear time.

Right, didn't actually think that through.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 12, 2023
@rfcbot
Copy link

rfcbot commented May 12, 2023

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.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label May 12, 2023
@bors bors closed this as completed in 5b58471 May 17, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label May 25, 2023
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants