diff options
Diffstat (limited to 'ctr-std/src/ffi/os_str.rs')
| -rw-r--r-- | ctr-std/src/ffi/os_str.rs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/ctr-std/src/ffi/os_str.rs b/ctr-std/src/ffi/os_str.rs index 0a31480..6bcd62d 100644 --- a/ctr-std/src/ffi/os_str.rs +++ b/ctr-std/src/ffi/os_str.rs @@ -348,6 +348,12 @@ impl OsString { #[stable(feature = "rust1", since = "1.0.0")] impl From<String> for OsString { + /// Converts a [`String`] into a [`OsString`]. + /// + /// The conversion copies the data, and includes an allocation on the heap. + /// + /// [`String`]: ../string/struct.String.html + /// [`OsString`]: struct.OsString.html fn from(s: String) -> OsString { OsString { inner: Buf::from_string(s) } } @@ -417,6 +423,20 @@ impl PartialEq<OsString> for str { } } +#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")] +impl<'a> PartialEq<&'a str> for OsString { + fn eq(&self, other: &&'a str) -> bool { + **self == **other + } +} + +#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")] +impl<'a> PartialEq<OsString> for &'a str { + fn eq(&self, other: &OsString) -> bool { + **other == **self + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Eq for OsString {} @@ -500,10 +520,12 @@ impl OsStr { /// Converts an `OsStr` to a [`Cow`]`<`[`str`]`>`. /// - /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. + /// Any non-Unicode sequences are replaced with + /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]. /// /// [`Cow`]: ../../std/borrow/enum.Cow.html /// [`str`]: ../../std/primitive.str.html + /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html /// /// # Examples /// @@ -616,6 +638,10 @@ impl<'a> From<&'a OsStr> for Box<OsStr> { #[stable(feature = "os_string_from_box", since = "1.18.0")] impl From<Box<OsStr>> for OsString { + /// Converts a `Box<OsStr>` into a `OsString` without copying or allocating. + /// + /// [`Box`]: ../boxed/struct.Box.html + /// [`OsString`]: ../ffi/struct.OsString.html fn from(boxed: Box<OsStr>) -> OsString { boxed.into_os_string() } @@ -623,13 +649,29 @@ impl From<Box<OsStr>> for OsString { #[stable(feature = "box_from_os_string", since = "1.20.0")] impl From<OsString> for Box<OsStr> { + /// Converts a [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating. + /// + /// [`Box`]: ../boxed/struct.Box.html + /// [`OsString`]: ../ffi/struct.OsString.html fn from(s: OsString) -> Box<OsStr> { s.into_boxed_os_str() } } +#[stable(feature = "more_box_slice_clone", since = "1.29.0")] +impl Clone for Box<OsStr> { + #[inline] + fn clone(&self) -> Self { + self.to_os_string().into_boxed_os_str() + } +} + #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From<OsString> for Arc<OsStr> { + /// Converts a [`OsString`] into a [`Arc`]`<OsStr>` without copying or allocating. + /// + /// [`Arc`]: ../sync/struct.Arc.html + /// [`OsString`]: ../ffi/struct.OsString.html #[inline] fn from(s: OsString) -> Arc<OsStr> { let arc = s.inner.into_arc(); @@ -648,6 +690,10 @@ impl<'a> From<&'a OsStr> for Arc<OsStr> { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From<OsString> for Rc<OsStr> { + /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating. + /// + /// [`Rc`]: ../rc/struct.Rc.html + /// [`OsString`]: ../ffi/struct.OsString.html #[inline] fn from(s: OsString) -> Rc<OsStr> { let rc = s.inner.into_rc(); |