-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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::bytes
#112115
Labels
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.
Comments
clarfonthey
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
May 30, 2023
Going through old branches and figured I might as well include the diff for the diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs
index dbdbaccb535..d571e9acb3c 100644
--- a/library/core/src/ffi/c_str.rs
+++ b/library/core/src/ffi/c_str.rs
@@ -783,6 +783,23 @@ fn is_empty(&self) -> bool {
// the nul terminator.
unsafe { self.ptr.read() == 0 }
}
+
+ /// Returns the remainder of the string as a slice.
+ #[unstable(feature = "cstr_bytes", issue = "none")]
+ #[inline]
+ pub fn as_c_str(&self) -> &'a CStr {
+ // SAFETY: We start with a valid C string and never increment beyond the
+ // nul terminator, retaining a valid C string, even if it's empty.
+ unsafe { CStr::from_ptr(self.ptr.as_ptr().cast_const().cast()) }
+ }
+}
+
+#[unstable(feature = "cstr_bytes", issue = "none")]
+impl AsRef<CStr> for Bytes<'_> {
+ #[inline]
+ fn as_ref(&self) -> &CStr {
+ self.as_c_str()
+ }
}
#[unstable(feature = "cstr_bytes", issue = "112115")] |
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Jul 16, 2024
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator cc tracking issue rust-lang#112115
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Jul 16, 2024
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator cc tracking issue rust-lang#112115
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Jul 16, 2024
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator cc tracking issue rust-lang#112115
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Jul 17, 2024
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator cc tracking issue rust-lang#112115
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jul 17, 2024
Rollup merge of rust-lang#127444 - Sky9x:cstr-bytes-iter, r=dtolnay `impl Send + Sync` and override `count` for the `CStr::bytes` iterator cc tracking issue rust-lang#112115
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.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Feature gate:
#![feature(cstr_bytes)]
This is a tracking issue for the
CStr::bytes
API.Public API
Steps / History
CStr::bytes
iterator libs-team#135impl Send + Sync
and overridecount
for theCStr::bytes
iterator #127444Unresolved Questions
std::ffi::c
andstd::ffi::os
submodules libs-team#134. (Resolution: Store incore::ffi::c_str
.)AsRef<CStr>
andas_c_str
method be added toCStrBytes
to reflect theslice::Iter
API?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html ↩
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: