From 7f3bb398fa90d68c737dd7e00a3813e0620ba472 Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Wed, 10 Jun 2020 23:13:45 +0200 Subject: Add a TryFrom> impl that mirror from_vec_with_nul --- src/libstd/ffi/c_str.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/libstd/ffi') diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 6f7dc091897..3a3b51fd353 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -1,6 +1,7 @@ use crate::ascii; use crate::borrow::{Borrow, Cow}; use crate::cmp::Ordering; +use crate::convert::TryFrom; use crate::error::Error; use crate::fmt::{self, Write}; use crate::io; @@ -853,6 +854,19 @@ impl From> for CString { } } +#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")] +impl TryFrom> for CString { + type Error = FromBytesWithNulError; + + /// See the document about [`from_vec_with_nul`] for more + /// informations about the behaviour of this method. + /// + /// [`from_vec_with_nul`]: struct.CString.html#method.from_vec_with_nul + fn try_from(value: Vec) -> Result { + Self::from_vec_with_nul(value) + } +} + #[stable(feature = "more_box_slice_clone", since = "1.29.0")] impl Clone for Box { #[inline] -- cgit 1.4.1-3-g733a5