stabilize CString::from_vec_with_nul[_unchecked]
This commit is contained in:
parent
3d71e749a2
commit
86b3dd9e0a
2 changed files with 9 additions and 13 deletions
|
@ -251,13 +251,12 @@ pub struct FromBytesWithNulError {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::{CString, FromVecWithNulError};
|
/// use std::ffi::{CString, FromVecWithNulError};
|
||||||
///
|
///
|
||||||
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err();
|
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"f\0oo".to_vec()).unwrap_err();
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
pub struct FromVecWithNulError {
|
pub struct FromVecWithNulError {
|
||||||
error_kind: FromBytesWithNulErrorKind,
|
error_kind: FromBytesWithNulErrorKind,
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
|
@ -278,7 +277,7 @@ impl FromBytesWithNulError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
impl FromVecWithNulError {
|
impl FromVecWithNulError {
|
||||||
/// Returns a slice of [`u8`]s bytes that were attempted to convert to a [`CString`].
|
/// Returns a slice of [`u8`]s bytes that were attempted to convert to a [`CString`].
|
||||||
///
|
///
|
||||||
|
@ -287,7 +286,6 @@ impl FromVecWithNulError {
|
||||||
/// Basic usage:
|
/// Basic usage:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::CString;
|
/// use std::ffi::CString;
|
||||||
///
|
///
|
||||||
/// // Some invalid bytes in a vector
|
/// // Some invalid bytes in a vector
|
||||||
|
@ -298,6 +296,7 @@ impl FromVecWithNulError {
|
||||||
/// assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
|
/// assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
pub fn as_bytes(&self) -> &[u8] {
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
&self.bytes[..]
|
&self.bytes[..]
|
||||||
}
|
}
|
||||||
|
@ -313,7 +312,6 @@ impl FromVecWithNulError {
|
||||||
/// Basic usage:
|
/// Basic usage:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::CString;
|
/// use std::ffi::CString;
|
||||||
///
|
///
|
||||||
/// // Some invalid bytes in a vector
|
/// // Some invalid bytes in a vector
|
||||||
|
@ -324,6 +322,7 @@ impl FromVecWithNulError {
|
||||||
/// assert_eq!(bytes, value.unwrap_err().into_bytes());
|
/// assert_eq!(bytes, value.unwrap_err().into_bytes());
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "`self` will be dropped if the result is not used"]
|
#[must_use = "`self` will be dropped if the result is not used"]
|
||||||
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
pub fn into_bytes(self) -> Vec<u8> {
|
pub fn into_bytes(self) -> Vec<u8> {
|
||||||
self.bytes
|
self.bytes
|
||||||
}
|
}
|
||||||
|
@ -704,7 +703,6 @@ impl CString {
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::CString;
|
/// use std::ffi::CString;
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// unsafe { CString::from_vec_with_nul_unchecked(b"abc\0".to_vec()) },
|
/// unsafe { CString::from_vec_with_nul_unchecked(b"abc\0".to_vec()) },
|
||||||
|
@ -712,7 +710,7 @@ impl CString {
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
pub unsafe fn from_vec_with_nul_unchecked(v: Vec<u8>) -> Self {
|
pub unsafe fn from_vec_with_nul_unchecked(v: Vec<u8>) -> Self {
|
||||||
Self { inner: v.into_boxed_slice() }
|
Self { inner: v.into_boxed_slice() }
|
||||||
}
|
}
|
||||||
|
@ -733,7 +731,6 @@ impl CString {
|
||||||
/// when called without the ending nul byte.
|
/// when called without the ending nul byte.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::CString;
|
/// use std::ffi::CString;
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// CString::from_vec_with_nul(b"abc\0".to_vec())
|
/// CString::from_vec_with_nul(b"abc\0".to_vec())
|
||||||
|
@ -745,14 +742,13 @@ impl CString {
|
||||||
/// An incorrectly formatted [`Vec`] will produce an error.
|
/// An incorrectly formatted [`Vec`] will produce an error.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(cstring_from_vec_with_nul)]
|
|
||||||
/// use std::ffi::{CString, FromVecWithNulError};
|
/// use std::ffi::{CString, FromVecWithNulError};
|
||||||
/// // Interior nul byte
|
/// // Interior nul byte
|
||||||
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"a\0bc".to_vec()).unwrap_err();
|
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"a\0bc".to_vec()).unwrap_err();
|
||||||
/// // No nul byte
|
/// // No nul byte
|
||||||
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"abc".to_vec()).unwrap_err();
|
/// let _: FromVecWithNulError = CString::from_vec_with_nul(b"abc".to_vec()).unwrap_err();
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
pub fn from_vec_with_nul(v: Vec<u8>) -> Result<Self, FromVecWithNulError> {
|
pub fn from_vec_with_nul(v: Vec<u8>) -> Result<Self, FromVecWithNulError> {
|
||||||
let nul_pos = memchr::memchr(0, &v);
|
let nul_pos = memchr::memchr(0, &v);
|
||||||
match nul_pos {
|
match nul_pos {
|
||||||
|
@ -1084,10 +1080,10 @@ impl fmt::Display for FromBytesWithNulError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
impl Error for FromVecWithNulError {}
|
impl Error for FromVecWithNulError {}
|
||||||
|
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
|
||||||
impl fmt::Display for FromVecWithNulError {
|
impl fmt::Display for FromVecWithNulError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.error_kind {
|
match self.error_kind {
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
|
|
||||||
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
|
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
|
||||||
pub use self::c_str::FromBytesWithNulError;
|
pub use self::c_str::FromBytesWithNulError;
|
||||||
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
|
#[stable(feature = "cstring_from_vec_with_nul", since = "1.57.0")]
|
||||||
pub use self::c_str::FromVecWithNulError;
|
pub use self::c_str::FromVecWithNulError;
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub use self::c_str::{CStr, CString, IntoStringError, NulError};
|
pub use self::c_str::{CStr, CString, IntoStringError, NulError};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue