Skip to content

Commit 5ca44de

Browse files
committed
Implemented FromStr for CString
1 parent b0af276 commit 5ca44de

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/alloc/src/ffi/c_str.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::borrow::Borrow;
77
use core::ffi::{c_char, CStr};
88
use core::num::NonZero;
99
use core::slice::memchr;
10-
use core::str::{self, Utf8Error};
10+
use core::str::{self, FromStr, Utf8Error};
1111
use core::{fmt, mem, ops, ptr, slice};
1212

1313
use crate::borrow::{Cow, ToOwned};
@@ -815,6 +815,15 @@ impl From<Vec<NonZero<u8>>> for CString {
815815
}
816816
}
817817

818+
impl FromStr for CString {
819+
type Err = NulError;
820+
821+
#[inline]
822+
fn from_str(s: &str) -> Result<Self, Self::Err> {
823+
Self::new(s)
824+
}
825+
}
826+
818827
#[cfg(not(test))]
819828
#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
820829
impl Clone for Box<CStr> {

0 commit comments

Comments
 (0)