Skip to content

Commit 20687bb

Browse files
authored
Rollup merge of #89292 - CleanCut:stabilize-cstring_from_vec_with_nul, r=JohnTitor
Stabilize CString::from_vec_with_nul[_unchecked] Closes the tracking issue #73179. I am keeping this in _draft_ mode until the FCP has ended. This is my first time stabilizing a feature, so I would appreciate any guidance on things I should do differently. Closes #73179
2 parents 6f0acbc + 39af41e commit 20687bb

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

library/std/src/ffi/c_str.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,12 @@ pub struct FromBytesWithNulError {
251251
/// # Examples
252252
///
253253
/// ```
254-
/// #![feature(cstring_from_vec_with_nul)]
255254
/// use std::ffi::{CString, FromVecWithNulError};
256255
///
257256
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err();
258257
/// ```
259258
#[derive(Clone, PartialEq, Eq, Debug)]
260-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
259+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
261260
pub struct FromVecWithNulError {
262261
error_kind: FromBytesWithNulErrorKind,
263262
bytes: Vec<u8>,
@@ -278,7 +277,7 @@ impl FromBytesWithNulError {
278277
}
279278
}
280279

281-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
280+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
282281
impl FromVecWithNulError {
283282
/// Returns a slice of [`u8`]s bytes that were attempted to convert to a [`CString`].
284283
///
@@ -287,7 +286,6 @@ impl FromVecWithNulError {
287286
/// Basic usage:
288287
///
289288
/// ```
290-
/// #![feature(cstring_from_vec_with_nul)]
291289
/// use std::ffi::CString;
292290
///
293291
/// // Some invalid bytes in a vector
@@ -298,6 +296,7 @@ impl FromVecWithNulError {
298296
/// assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
299297
/// ```
300298
#[must_use]
299+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
301300
pub fn as_bytes(&self) -> &[u8] {
302301
&self.bytes[..]
303302
}
@@ -313,7 +312,6 @@ impl FromVecWithNulError {
313312
/// Basic usage:
314313
///
315314
/// ```
316-
/// #![feature(cstring_from_vec_with_nul)]
317315
/// use std::ffi::CString;
318316
///
319317
/// // Some invalid bytes in a vector
@@ -324,6 +322,7 @@ impl FromVecWithNulError {
324322
/// assert_eq!(bytes, value.unwrap_err().into_bytes());
325323
/// ```
326324
#[must_use = "`self` will be dropped if the result is not used"]
325+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
327326
pub fn into_bytes(self) -> Vec<u8> {
328327
self.bytes
329328
}
@@ -704,15 +703,14 @@ impl CString {
704703
/// # Example
705704
///
706705
/// ```
707-
/// #![feature(cstring_from_vec_with_nul)]
708706
/// use std::ffi::CString;
709707
/// assert_eq!(
710708
/// unsafe { CString::from_vec_with_nul_unchecked(b"abc\0".to_vec()) },
711709
/// unsafe { CString::from_vec_unchecked(b"abc".to_vec()) }
712710
/// );
713711
/// ```
714712
#[must_use]
715-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
713+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
716714
pub unsafe fn from_vec_with_nul_unchecked(v: Vec<u8>) -> Self {
717715
Self { inner: v.into_boxed_slice() }
718716
}
@@ -733,7 +731,6 @@ impl CString {
733731
/// when called without the ending nul byte.
734732
///
735733
/// ```
736-
/// #![feature(cstring_from_vec_with_nul)]
737734
/// use std::ffi::CString;
738735
/// assert_eq!(
739736
/// CString::from_vec_with_nul(b"abc\0".to_vec())
@@ -745,14 +742,13 @@ impl CString {
745742
/// An incorrectly formatted [`Vec`] will produce an error.
746743
///
747744
/// ```
748-
/// #![feature(cstring_from_vec_with_nul)]
749745
/// use std::ffi::{CString, FromVecWithNulError};
750746
/// // Interior nul byte
751747
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"a\0bc".to_vec()).unwrap_err();
752748
/// // No nul byte
753749
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"abc".to_vec()).unwrap_err();
754750
/// ```
755-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
751+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
756752
pub fn from_vec_with_nul(v: Vec<u8>) -> Result<Self, FromVecWithNulError> {
757753
let nul_pos = memchr::memchr(0, &v);
758754
match nul_pos {
@@ -1084,10 +1080,10 @@ impl fmt::Display for FromBytesWithNulError {
10841080
}
10851081
}
10861082

1087-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
1083+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
10881084
impl Error for FromVecWithNulError {}
10891085

1090-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
1086+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
10911087
impl fmt::Display for FromVecWithNulError {
10921088
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10931089
match self.error_kind {

library/std/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145

146146
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
147147
pub use self::c_str::FromBytesWithNulError;
148-
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
148+
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
149149
pub use self::c_str::FromVecWithNulError;
150150
#[stable(feature = "rust1", since = "1.0.0")]
151151
pub use self::c_str::{CStr, CString, IntoStringError, NulError};

0 commit comments

Comments
 (0)