Skip to content

Commit 7f3bb39

Browse files
committed
Add a TryFrom<Vec<u8>> impl that mirror from_vec_with_nul
1 parent b03164e commit 7f3bb39

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/ffi/c_str.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::ascii;
22
use crate::borrow::{Borrow, Cow};
33
use crate::cmp::Ordering;
4+
use crate::convert::TryFrom;
45
use crate::error::Error;
56
use crate::fmt::{self, Write};
67
use crate::io;
@@ -853,6 +854,19 @@ impl From<Vec<NonZeroU8>> for CString {
853854
}
854855
}
855856

857+
#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
858+
impl TryFrom<Vec<u8>> for CString {
859+
type Error = FromBytesWithNulError;
860+
861+
/// See the document about [`from_vec_with_nul`] for more
862+
/// informations about the behaviour of this method.
863+
///
864+
/// [`from_vec_with_nul`]: struct.CString.html#method.from_vec_with_nul
865+
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
866+
Self::from_vec_with_nul(value)
867+
}
868+
}
869+
856870
#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
857871
impl Clone for Box<CStr> {
858872
#[inline]

0 commit comments

Comments
 (0)