Skip to content

Commit

Permalink
Add a TryFrom<Vec<u8>> impl that mirror from_vec_with_nul
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Jun 10, 2020
1 parent b03164e commit 7f3bb39
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -853,6 +854,19 @@ impl From<Vec<NonZeroU8>> for CString {
}
}

#[unstable(feature = "cstring_from_vec_with_nul", issue = "73179")]
impl TryFrom<Vec<u8>> 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<u8>) -> Result<Self, Self::Error> {
Self::from_vec_with_nul(value)
}
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<CStr> {
#[inline]
Expand Down

0 comments on commit 7f3bb39

Please sign in to comment.