We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2835a66 commit 1867de5Copy full SHA for 1867de5
library/core/src/ffi/c_str.rs
@@ -731,6 +731,23 @@ impl<'a> CStrBytes<'a> {
731
// the nul terminator.
732
unsafe { *self.ptr.as_ref() == 0 }
733
}
734
+
735
+ /// Returns the remainder of the string as a slice.
736
+ #[unstable(feature = "cstr_bytes", issue = "none")]
737
+ #[inline]
738
+ pub fn as_c_str(&self) -> &'a CStr {
739
+ // SAFETY: We start with a valid C string and never increment beyond the
740
+ // nul terminator, retaining a valid C string, even if it's empty.
741
+ unsafe { CStr::from_ptr(self.ptr.as_ptr() as *mut u8 as *const c_char) }
742
+ }
743
+}
744
745
+#[unstable(feature = "cstr_bytes", issue = "none")]
746
+impl AsRef<CStr> for CStrBytes<'_> {
747
748
+ fn as_ref(&self) -> &CStr {
749
+ self.as_c_str()
750
751
752
753
#[unstable(feature = "cstr_bytes", issue = "none")]
0 commit comments