From 71033fe1bec5610a57457d4d0e4626c3d5570cef Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Sat, 22 Jul 2023 23:21:18 -0400 Subject: [PATCH] Use new "os_str_bytes" methods --- src/lib.rs | 5 +++-- src/raw_str.rs | 21 ++++----------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a315cf1..a8813ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,8 +107,8 @@ //! These features are unstable, since they rely on unstable Rust features. //! //! - **nightly** - -//! Changes the implementation to use [`OsStr::as_os_str_bytes`] and -//! [`OsStr::from_os_str_bytes_unchecked`] and provides: +//! Changes the implementation to use the ["os\_str\_bytes" nightly +//! feature][feature] and provides: //! - [`RawOsStr::as_os_str`] //! - [`RawOsStr::assert_cow_from_raw_bytes`] //! - [`RawOsStr::as_os_str_bytes`] @@ -181,6 +181,7 @@ //! [bstr]: https://crates.io/crates/bstr //! [`ByteSlice::to_os_str`]: https://docs.rs/bstr/0.2.12/bstr/trait.ByteSlice.html#method.to_os_str //! [`ByteVec::into_os_string`]: https://docs.rs/bstr/0.2.12/bstr/trait.ByteVec.html#method.into_os_string +//! [feature]: https://doc.rust-lang.org/unstable-book/library-features/os-str-bytes.html //! [memchr complexity]: RawOsStr#complexity //! [memchr]: https://crates.io/crates/memchr //! [`OsStrExt`]: ::std::os::unix::ffi::OsStrExt diff --git a/src/raw_str.rs b/src/raw_str.rs index c92febd..c85f53e 100644 --- a/src/raw_str.rs +++ b/src/raw_str.rs @@ -72,17 +72,6 @@ unsafe trait TransmuteBox { unsafe impl TransmuteBox for RawOsStr {} unsafe impl TransmuteBox for [u8] {} -if_nightly! { - unsafe fn from_os_str_vec_unchecked(string: Vec) -> OsString { - // SAFETY: This function has equivalent safety requirements. - unsafe { OsStr::from_os_str_bytes_unchecked(&string) }.to_owned() - } - - fn into_os_str_vec(os_string: OsString) -> Vec { - os_string.as_os_str_bytes().to_owned() - } -} - /// A container for borrowed byte strings converted by this crate. /// /// This wrapper is intended to prevent violating the invariants of the @@ -1504,7 +1493,7 @@ impl RawOsString { #[must_use] pub fn new(string: OsString) -> Self { if_nightly_return! {{ - Self(into_os_str_vec(string)) + Self(string.into_os_str_bytes()) }} Self(imp::os_string_into_vec(string)) } @@ -1676,8 +1665,7 @@ impl RawOsString { } if_nightly! { - /// Equivalent to [`OsStr::from_os_str_bytes_unchecked`] but accepts an - /// owned byte string. + /// Equivalent to [`OsString::from_os_str_bytes_unchecked`]. /// /// # Examples /// @@ -1769,7 +1757,7 @@ impl RawOsString { if_nightly_return! {{ // SAFETY: This wrapper prevents violating the invariants of the // encoding used by the standard library. - unsafe { from_os_str_vec_unchecked(self.0) } + unsafe { OsString::from_os_str_bytes_unchecked(self.0) } }} expect_encoded!(imp::os_string_from_vec(self.0)) } @@ -1799,8 +1787,7 @@ impl RawOsString { } if_nightly! { - /// Equivalent to [`OsStr::as_os_str_bytes`] but produces an owned byte - /// string. + /// Equivalent to [`OsString::into_os_str_bytes`]. /// /// The returned string will not use the [unspecified encoding]. It can /// only be passed to methods accepting the encoding from the standard