Skip to content

Commit

Permalink
Implemented FromStr for CString
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Sep 20, 2024
1 parent b0af276 commit 5ca44de
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::borrow::Borrow;
use core::ffi::{c_char, CStr};
use core::num::NonZero;
use core::slice::memchr;
use core::str::{self, Utf8Error};
use core::str::{self, FromStr, Utf8Error};
use core::{fmt, mem, ops, ptr, slice};

use crate::borrow::{Cow, ToOwned};
Expand Down Expand Up @@ -815,6 +815,15 @@ impl From<Vec<NonZero<u8>>> for CString {
}
}

impl FromStr for CString {
type Err = NulError;

#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::new(s)
}
}

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

0 comments on commit 5ca44de

Please sign in to comment.