Skip to content

Commit b81ee0b

Browse files
committed
Document From conversions for CString and CStr
1 parent acdafa0 commit b81ee0b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/libstd/ffi/c_str.rs

+25
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,11 @@ impl fmt::Debug for CString {
642642

643643
#[stable(feature = "cstring_into", since = "1.7.0")]
644644
impl From<CString> for Vec<u8> {
645+
/// Converts a [`CString`] into a [`Vec`]`<u8>`.
646+
/// The conversion consumes the [`CString`], and removes the terminating NUL byte.
647+
///
648+
/// [`Vec`]: ../vec/struct.Vec.html
649+
/// [`CString`]: ../ffi/struct.CString.html
645650
#[inline]
646651
fn from(s: CString) -> Vec<u8> {
647652
s.into_bytes()
@@ -700,6 +705,10 @@ impl<'a> From<&'a CStr> for Box<CStr> {
700705

701706
#[stable(feature = "c_string_from_box", since = "1.18.0")]
702707
impl From<Box<CStr>> for CString {
708+
/// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating.
709+
///
710+
/// [`Box`]: ../boxed/struct.Box.html
711+
/// [`CString`]: ../ffi/struct.CString.html
703712
#[inline]
704713
fn from(s: Box<CStr>) -> CString {
705714
s.into_c_string()
@@ -716,6 +725,10 @@ impl Clone for Box<CStr> {
716725

717726
#[stable(feature = "box_from_c_string", since = "1.20.0")]
718727
impl From<CString> for Box<CStr> {
728+
/// Converts a [`CString`] into a [`Box`]`<CStr>` without copying or allocating.
729+
///
730+
/// [`CString`]: ../ffi/struct.CString.html
731+
/// [`Box`]: ../boxed/struct.Box.html
719732
#[inline]
720733
fn from(s: CString) -> Box<CStr> {
721734
s.into_boxed_c_str()
@@ -748,6 +761,10 @@ impl<'a> From<&'a CString> for Cow<'a, CStr> {
748761

749762
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
750763
impl From<CString> for Arc<CStr> {
764+
/// Converts a [`CString`] into a [`Arc`]`<CStr>` without copying or allocating.
765+
///
766+
/// [`CString`]: ../ffi/struct.CString.html
767+
/// [`Arc`]: ../sync/struct.Arc.html
751768
#[inline]
752769
fn from(s: CString) -> Arc<CStr> {
753770
let arc: Arc<[u8]> = Arc::from(s.into_inner());
@@ -766,6 +783,10 @@ impl<'a> From<&'a CStr> for Arc<CStr> {
766783

767784
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
768785
impl From<CString> for Rc<CStr> {
786+
/// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.
787+
///
788+
/// [`CString`]: ../ffi/struct.CString.html
789+
/// [`Rc`]: ../rc/struct.Rc.html
769790
#[inline]
770791
fn from(s: CString) -> Rc<CStr> {
771792
let rc: Rc<[u8]> = Rc::from(s.into_inner());
@@ -839,6 +860,10 @@ impl fmt::Display for NulError {
839860

840861
#[stable(feature = "rust1", since = "1.0.0")]
841862
impl From<NulError> for io::Error {
863+
/// Converts a [`NulError`] into a [`io::Error`].
864+
///
865+
/// [`NulError`]: ../ffi/struct.NulError.html
866+
/// [`io::Error`]: ../io/struct.Error.html
842867
fn from(_: NulError) -> io::Error {
843868
io::Error::new(io::ErrorKind::InvalidInput,
844869
"data provided contains a nul byte")

0 commit comments

Comments
 (0)