Skip to content

Commit acdafa0

Browse files
committed
Document From conversions for OsString and OsStr
1 parent 50702b2 commit acdafa0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libstd/ffi/os_str.rs

+21
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ impl OsString {
348348

349349
#[stable(feature = "rust1", since = "1.0.0")]
350350
impl From<String> for OsString {
351+
/// Converts a [`String`] into a [`OsString`].
352+
/// The conversion copies the data, and includes an allocation on the heap.
353+
///
354+
/// [`String`]: ../string/struct.String.html
355+
/// [`OsString`]: struct.OsString.html
351356
fn from(s: String) -> OsString {
352357
OsString { inner: Buf::from_string(s) }
353358
}
@@ -630,13 +635,21 @@ impl<'a> From<&'a OsStr> for Box<OsStr> {
630635

631636
#[stable(feature = "os_string_from_box", since = "1.18.0")]
632637
impl From<Box<OsStr>> for OsString {
638+
/// Converts a `Box<OsStr>` into a `OsString` without copying or allocating.
639+
///
640+
/// [`Box`]: ../boxed/struct.Box.html
641+
/// [`OsString`]: ../ffi/struct.OsString.html
633642
fn from(boxed: Box<OsStr>) -> OsString {
634643
boxed.into_os_string()
635644
}
636645
}
637646

638647
#[stable(feature = "box_from_os_string", since = "1.20.0")]
639648
impl From<OsString> for Box<OsStr> {
649+
/// Converts a [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating.
650+
///
651+
/// [`Box`]: ../boxed/struct.Box.html
652+
/// [`OsString`]: ../ffi/struct.OsString.html
640653
fn from(s: OsString) -> Box<OsStr> {
641654
s.into_boxed_os_str()
642655
}
@@ -652,6 +665,10 @@ impl Clone for Box<OsStr> {
652665

653666
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
654667
impl From<OsString> for Arc<OsStr> {
668+
/// Converts a [`OsString`] into a [`Arc`]`<OsStr>` without copying or allocating.
669+
///
670+
/// [`Arc`]: ../sync/struct.Arc.html
671+
/// [`OsString`]: ../ffi/struct.OsString.html
655672
#[inline]
656673
fn from(s: OsString) -> Arc<OsStr> {
657674
let arc = s.inner.into_arc();
@@ -670,6 +687,10 @@ impl<'a> From<&'a OsStr> for Arc<OsStr> {
670687

671688
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
672689
impl From<OsString> for Rc<OsStr> {
690+
/// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating.
691+
///
692+
/// [`Rc`]: ../rc/struct.Rc.html
693+
/// [`OsString`]: ../ffi/struct.OsString.html
673694
#[inline]
674695
fn from(s: OsString) -> Rc<OsStr> {
675696
let rc = s.inner.into_rc();

0 commit comments

Comments
 (0)