Skip to content

Commit

Permalink
Use new "os_str_bytes" methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Jul 23, 2023
1 parent eff3b37 commit 71033fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down Expand Up @@ -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
Expand Down
21 changes: 4 additions & 17 deletions src/raw_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> 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<u8> {
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
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 71033fe

Please sign in to comment.