From 6870f75cef3f480121e5316a228196b8bbaa838b Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:51:51 -0400 Subject: [PATCH] Increase MSRV to 1.74.0 --- .github/workflows/build.yml | 5 +- Cargo.toml | 4 +- README.md | 12 +- src/common/raw.rs | 42 +- src/lib.rs | 857 +++++++++++++++++------------------- src/raw_str.rs | 573 +++++++++--------------- src/wasm/raw.rs | 33 -- src/windows/raw.rs | 43 +- src/windows/wtf8/string.rs | 11 +- tests/raw_index.rs | 37 +- tests/raw_integration.rs | 4 - tests/raw_random.rs | 3 +- 12 files changed, 629 insertions(+), 995 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4785454..e667b7b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,6 @@ name: build env: OS_STR_BYTES_CHECKED_CONVERSIONS: 1 - OS_STR_BYTES_NIGHTLY: 1 on: pull_request: @@ -27,7 +26,7 @@ jobs: cargo fmt --check shell: bash env: - cargo_hack_options: --feature-powerset --optional-deps --exclude-features nightly + cargo_hack_options: --feature-powerset --optional-deps timeout-minutes: 10 strategy: matrix: @@ -38,7 +37,6 @@ jobs: steps: - uses: dylni/build-actions/build-other@master with: - nightly-features: 'nightly print_bytes uniquote' target: ${{ matrix.target }} version: ${{ matrix.version }} timeout-minutes: 10 @@ -55,7 +53,6 @@ jobs: steps: - uses: dylni/build-actions/test@master with: - nightly-features: 'nightly print_bytes uniquote' version: ${{ matrix.version }} - run: cargo test --no-default-features --features raw_os_str timeout-minutes: 10 diff --git a/Cargo.toml b/Cargo.toml index 841b059..5116367 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "os_str_bytes" version = "6.6.1" authors = ["dylni"] edition = "2021" -rust-version = "1.61.0" +rust-version = "1.74.0" description = """ Convert between byte sequences and platform-native strings """ @@ -31,8 +31,6 @@ lazy_static = "1.4" [features] default = ["memchr", "raw_os_str"] -nightly = [] - checked_conversions = ["conversions"] conversions = [] raw_os_str = [] diff --git a/README.md b/README.md index 4c676bb..5255c63 100644 --- a/README.md +++ b/README.md @@ -47,32 +47,32 @@ The minimum supported Rust toolchain version depends on the platform:
*-*-solid_asp3(-*)
*-wasi
wasm32-*-unknown
*-*-windows-*
*-*-xous-*
(&self, pat: P) -> bool - where - P: Pattern; - - /// Equivalent to [`str::ends_with`]. - /// - /// # Examples - /// - /// ``` - /// use std::ffi::OsStr; - /// - /// use os_str_bytes::OsStrBytesExt; - /// - /// let os_string = OsStr::new("foobar"); - /// assert!(os_string.ends_with("bar")); - /// assert!(!os_string.ends_with("foo")); - /// ``` - #[must_use] - fn ends_with
(&self, pat: P) -> bool - where - P: Pattern; - - if_conversions! { - /// Equivalent to [`str::ends_with`] but accepts this type for - /// the pattern. - /// - /// # Examples - /// - /// ``` - /// use std::ffi::OsStr; - /// - /// use os_str_bytes::OsStrBytesExt; - /// - /// let os_string = OsStr::new("foobar"); - /// assert!(os_string.ends_with_os(OsStr::new("bar"))); - /// assert!(!os_string.ends_with_os(OsStr::new("foo"))); - /// ``` - #[cfg_attr( - os_str_bytes_docs_rs, - doc(cfg(feature = "conversions")) - )] - #[must_use] - fn ends_with_os(&self, pat: &Self) -> bool; - } + #[cfg(not(feature = "conversions"))] + trait OsStrBytes: private::Sealed {} - /// Equivalent to [`str::find`]. - /// - /// # Examples - /// - /// ``` - /// use std::ffi::OsStr; - /// - /// use os_str_bytes::OsStrBytesExt; - /// - /// let os_string = OsStr::new("foobar"); - /// assert_eq!(Some(1), os_string.find("o")); - /// assert_eq!(None, os_string.find("of")); - /// ``` - #[must_use] - fn find
(&self, pat: P) -> Option (&self, pat: P) -> Option (&self, pat: P) -> bool
+ where
+ P: Pattern;
- /// Equivalent to [`str::rsplit_once`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("foobar");
- /// assert_eq!(
- /// Some((OsStr::new("fo"), OsStr::new("bar"))),
- /// os_string.rsplit_once("o"),
- /// );
- /// assert_eq!(None, os_string.rsplit_once("of"));
- /// ```
- #[must_use]
- fn rsplit_once (&self, pat: P) -> Option<(&Self, &Self)>
- where
- P: Pattern;
+ /// Equivalent to [`str::ends_with`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert!(os_string.ends_with("bar"));
+ /// assert!(!os_string.ends_with("foo"));
+ /// ```
+ #[must_use]
+ fn ends_with (&self, pat: P) -> bool
+ where
+ P: Pattern;
- /// Equivalent to [`str::split_at`].
- ///
- /// # Panics
- ///
- /// Panics if the index is not a [valid boundary].
+ if_conversions! {
+ /// Equivalent to [`str::ends_with`] but accepts this type for the
+ /// pattern.
///
/// # Examples
///
@@ -717,158 +568,141 @@ if_raw_str! {
/// use os_str_bytes::OsStrBytesExt;
///
/// let os_string = OsStr::new("foobar");
- /// assert_eq!(
- /// ((OsStr::new("fo"), OsStr::new("obar"))),
- /// os_string.split_at(2),
- /// );
+ /// assert!(os_string.ends_with_os(OsStr::new("bar")));
+ /// assert!(!os_string.ends_with_os(OsStr::new("foo")));
/// ```
- ///
- /// [valid boundary]: RawOsStr#indices
+ #[cfg_attr(
+ os_str_bytes_docs_rs,
+ doc(cfg(feature = "conversions"))
+ )]
#[must_use]
- #[track_caller]
- fn split_at(&self, mid: usize) -> (&Self, &Self);
+ fn ends_with_os(&self, pat: &Self) -> bool;
+ }
- /// Equivalent to [`str::split_once`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("foobar");
- /// assert_eq!(
- /// Some((OsStr::new("f"), OsStr::new("obar"))),
- /// os_string.split_once("o"),
- /// );
- /// assert_eq!(None, os_string.split_once("of"));
- /// ```
- #[must_use]
- fn split_once (&self, pat: P) -> Option<(&Self, &Self)>
- where
- P: Pattern;
+ /// Equivalent to [`str::find`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert_eq!(Some(1), os_string.find("o"));
+ /// assert_eq!(None, os_string.find("of"));
+ /// ```
+ #[must_use]
+ fn find (&self, pat: P) -> Option (&self, pat: P) -> bool
- where
- P: Pattern;
-
- if_conversions! {
- /// Equivalent to [`str::starts_with`] but accepts this type
- /// for the pattern.
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("foobar");
- /// assert!(os_string.starts_with_os(OsStr::new("foo")));
- /// assert!(!os_string.starts_with_os(OsStr::new("bar")));
- /// ```
- #[cfg_attr(
- os_str_bytes_docs_rs,
- doc(cfg(feature = "conversions"))
- )]
- #[must_use]
- fn starts_with_os(&self, pat: &Self) -> bool;
- }
+ /// Equivalent to [`str::rfind`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert_eq!(Some(2), os_string.rfind("o"));
+ /// assert_eq!(None, os_string.rfind("of"));
+ /// ```
+ #[must_use]
+ fn rfind (&self, pat: P) -> Option (&self, pat: P) -> Option<&Self>
- where
- P: Pattern;
+ /// Equivalent to [`str::rsplit_once`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert_eq!(
+ /// Some((OsStr::new("fo"), OsStr::new("bar"))),
+ /// os_string.rsplit_once("o"),
+ /// );
+ /// assert_eq!(None, os_string.rsplit_once("of"));
+ /// ```
+ #[must_use]
+ fn rsplit_once (&self, pat: P) -> Option<(&Self, &Self)>
+ where
+ P: Pattern;
- /// Equivalent to [`str::strip_suffix`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("111foo1bar111");
- /// assert_eq!(
- /// Some(OsStr::new("111foo1bar11")),
- /// os_string.strip_suffix("1"),
- /// );
- /// assert_eq!(None, os_string.strip_suffix("o"));
- /// ```
- #[must_use]
- fn strip_suffix (&self, pat: P) -> Option<&Self>
- where
- P: Pattern;
+ /// Equivalent to [`str::split_at`].
+ ///
+ /// # Panics
+ ///
+ /// Panics if the index is not a [valid boundary].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert_eq!(
+ /// ((OsStr::new("fo"), OsStr::new("obar"))),
+ /// os_string.split_at(2),
+ /// );
+ /// ```
+ ///
+ /// [valid boundary]: RawOsStr#indices
+ #[must_use]
+ #[track_caller]
+ fn split_at(&self, mid: usize) -> (&Self, &Self);
- /// Equivalent to [`str::trim_end_matches`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("111foo1bar111");
- /// assert_eq!("111foo1bar", os_string.trim_end_matches("1"));
- /// assert_eq!("111foo1bar111", os_string.trim_end_matches("o"));
- /// ```
- #[must_use]
- fn trim_end_matches (&self, pat: P) -> &Self
- where
- P: Pattern;
+ /// Equivalent to [`str::split_once`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert_eq!(
+ /// Some((OsStr::new("f"), OsStr::new("obar"))),
+ /// os_string.split_once("o"),
+ /// );
+ /// assert_eq!(None, os_string.split_once("of"));
+ /// ```
+ #[must_use]
+ fn split_once (&self, pat: P) -> Option<(&Self, &Self)>
+ where
+ P: Pattern;
- /// Equivalent to [`str::trim_matches`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::ffi::OsStr;
- ///
- /// use os_str_bytes::OsStrBytesExt;
- ///
- /// let os_string = OsStr::new("111foo1bar111");
- /// assert_eq!("foo1bar", os_string.trim_matches("1"));
- /// assert_eq!("111foo1bar111", os_string.trim_matches("o"));
- /// ```
- #[must_use]
- fn trim_matches (&self, pat: P) -> &Self
- where
- P: Pattern;
+ /// Equivalent to [`str::starts_with`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("foobar");
+ /// assert!(os_string.starts_with("foo"));
+ /// assert!(!os_string.starts_with("bar"));
+ /// ```
+ #[must_use]
+ fn starts_with (&self, pat: P) -> bool
+ where
+ P: Pattern;
- /// Equivalent to [`str::trim_start_matches`].
+ if_conversions! {
+ /// Equivalent to [`str::starts_with`] but accepts this type
+ /// for the pattern.
///
/// # Examples
///
@@ -877,147 +711,244 @@ if_raw_str! {
///
/// use os_str_bytes::OsStrBytesExt;
///
- /// let os_string = OsStr::new("111foo1bar111");
- /// assert_eq!("foo1bar111", os_string.trim_start_matches("1"));
- /// assert_eq!("111foo1bar111", os_string.trim_start_matches("o"));
+ /// let os_string = OsStr::new("foobar");
+ /// assert!(os_string.starts_with_os(OsStr::new("foo")));
+ /// assert!(!os_string.starts_with_os(OsStr::new("bar")));
/// ```
+ #[cfg_attr(
+ os_str_bytes_docs_rs,
+ doc(cfg(feature = "conversions"))
+ )]
#[must_use]
- fn trim_start_matches (&self, pat: P) -> &Self
- where
- P: Pattern;
+ fn starts_with_os(&self, pat: &Self) -> bool;
}
- impl OsStrBytesExt for OsStr {
- #[inline]
- fn contains (&self, pat: P) -> bool
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).contains(pat)
- }
+ /// Equivalent to [`str::strip_prefix`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("111foo1bar111");
+ /// assert_eq!(
+ /// Some(OsStr::new("11foo1bar111")),
+ /// os_string.strip_prefix("1"),
+ /// );
+ /// assert_eq!(None, os_string.strip_prefix("o"));
+ /// ```
+ #[must_use]
+ fn strip_prefix (&self, pat: P) -> Option<&Self>
+ where
+ P: Pattern;
- #[inline]
- fn ends_with (&self, pat: P) -> bool
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).ends_with(pat)
- }
+ /// Equivalent to [`str::strip_suffix`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("111foo1bar111");
+ /// assert_eq!(
+ /// Some(OsStr::new("111foo1bar11")),
+ /// os_string.strip_suffix("1"),
+ /// );
+ /// assert_eq!(None, os_string.strip_suffix("o"));
+ /// ```
+ #[must_use]
+ fn strip_suffix (&self, pat: P) -> Option<&Self>
+ where
+ P: Pattern;
- if_conversions! {
- #[inline]
- fn ends_with_os(&self, pat: &Self) -> bool {
- RawOsStr::from_os_str(self)
- .ends_with_os(RawOsStr::from_os_str(pat))
- }
- }
+ /// Equivalent to [`str::trim_end_matches`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::ffi::OsStr;
+ ///
+ /// use os_str_bytes::OsStrBytesExt;
+ ///
+ /// let os_string = OsStr::new("111foo1bar111");
+ /// assert_eq!("111foo1bar", os_string.trim_end_matches("1"));
+ /// assert_eq!("111foo1bar111", os_string.trim_end_matches("o"));
+ /// ```
+ #[must_use]
+ fn trim_end_matches (&self, pat: P) -> &Self
+ where
+ P: Pattern;
- #[inline]
- fn find (&self, pat: P) -> Option (&self, pat: P) -> &Self
+ where
+ P: Pattern;
- #[inline]
- fn rfind (&self, pat: P) -> Option (&self, pat: P) -> &Self
+ where
+ P: Pattern;
+ }
- #[inline]
- fn rsplit_once (&self, pat: P) -> Option<(&Self, &Self)>
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self)
- .rsplit_once(pat)
- .map(|(prefix, suffix)| {
- (prefix.as_os_str(), suffix.as_os_str())
- })
- }
+ impl OsStrBytesExt for OsStr {
+ #[inline]
+ fn contains (&self, pat: P) -> bool
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).contains(pat)
+ }
- #[inline]
- fn split_at(&self, mid: usize) -> (&Self, &Self) {
- let (prefix, suffix) =
- RawOsStr::from_os_str(self).split_at(mid);
- (prefix.as_os_str(), suffix.as_os_str())
- }
+ #[inline]
+ fn ends_with (&self, pat: P) -> bool
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).ends_with(pat)
+ }
+ if_conversions! {
#[inline]
- fn split_once (&self, pat: P) -> Option<(&Self, &Self)>
- where
- P: Pattern,
- {
+ fn ends_with_os(&self, pat: &Self) -> bool {
RawOsStr::from_os_str(self)
- .split_once(pat)
- .map(|(prefix, suffix)| {
- (prefix.as_os_str(), suffix.as_os_str())
- })
+ .ends_with_os(RawOsStr::from_os_str(pat))
}
+ }
- #[inline]
- fn starts_with (&self, pat: P) -> bool
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).starts_with(pat)
- }
+ #[inline]
+ fn find (&self, pat: P) -> Option (&self, pat: P) -> Option (&self, pat: P) -> Option<&Self>
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self)
- .strip_prefix(pat)
- .map(RawOsStr::as_os_str)
- }
+ #[inline]
+ fn rsplit_once (&self, pat: P) -> Option<(&Self, &Self)>
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self)
+ .rsplit_once(pat)
+ .map(|(prefix, suffix)| {
+ (prefix.as_os_str(), suffix.as_os_str())
+ })
+ }
+
+ #[inline]
+ fn split_at(&self, mid: usize) -> (&Self, &Self) {
+ let (prefix, suffix) = RawOsStr::from_os_str(self).split_at(mid);
+ (prefix.as_os_str(), suffix.as_os_str())
+ }
+
+ #[inline]
+ fn split_once (&self, pat: P) -> Option<(&Self, &Self)>
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self)
+ .split_once(pat)
+ .map(|(prefix, suffix)| {
+ (prefix.as_os_str(), suffix.as_os_str())
+ })
+ }
+
+ #[inline]
+ fn starts_with (&self, pat: P) -> bool
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).starts_with(pat)
+ }
+ if_conversions! {
#[inline]
- fn strip_suffix (&self, pat: P) -> Option<&Self>
- where
- P: Pattern,
- {
+ fn starts_with_os(&self, pat: &Self) -> bool {
RawOsStr::from_os_str(self)
- .strip_suffix(pat)
- .map(RawOsStr::as_os_str)
+ .starts_with_os(RawOsStr::from_os_str(pat))
}
+ }
- #[inline]
- fn trim_end_matches (&self, pat: P) -> &Self
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).trim_end_matches(pat).as_os_str()
- }
+ #[inline]
+ fn strip_prefix (&self, pat: P) -> Option<&Self>
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self)
+ .strip_prefix(pat)
+ .map(RawOsStr::as_os_str)
+ }
- #[inline]
- fn trim_matches (&self, pat: P) -> &Self
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).trim_matches(pat).as_os_str()
- }
+ #[inline]
+ fn strip_suffix (&self, pat: P) -> Option<&Self>
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self)
+ .strip_suffix(pat)
+ .map(RawOsStr::as_os_str)
+ }
- #[inline]
- fn trim_start_matches (&self, pat: P) -> &Self
- where
- P: Pattern,
- {
- RawOsStr::from_os_str(self).trim_start_matches(pat).as_os_str()
- }
+ #[inline]
+ fn trim_end_matches (&self, pat: P) -> &Self
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).trim_end_matches(pat).as_os_str()
+ }
+
+ #[inline]
+ fn trim_matches (&self, pat: P) -> &Self
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).trim_matches(pat).as_os_str()
+ }
+
+ #[inline]
+ fn trim_start_matches (&self, pat: P) -> &Self
+ where
+ P: Pattern,
+ {
+ RawOsStr::from_os_str(self).trim_start_matches(pat).as_os_str()
}
}
}
diff --git a/src/raw_str.rs b/src/raw_str.rs
index d694f46..6086fdc 100644
--- a/src/raw_str.rs
+++ b/src/raw_str.rs
@@ -1,5 +1,3 @@
-#![cfg_attr(feature = "nightly", allow(unreachable_code))]
-
use std::borrow::Borrow;
use std::borrow::Cow;
use std::borrow::ToOwned;
@@ -26,11 +24,11 @@ use memchr::memmem::find;
#[cfg(feature = "memchr")]
use memchr::memmem::rfind;
-use super::imp;
use super::imp::raw;
use super::iter::RawSplit;
use super::pattern::Encoded as EncodedPattern;
use super::private;
+use super::util;
use super::Pattern;
if_checked_conversions! {
@@ -38,8 +36,8 @@ if_checked_conversions! {
use super::Result;
}
-if_nightly! {
- use super::util;
+if_conversions! {
+ use super::imp;
}
#[cfg(not(feature = "memchr"))]
@@ -121,17 +119,7 @@ impl RawOsStr {
unsafe { mem::transmute(string) }
}
- /// Converts a platform-native string into a representation that can be
- /// more easily manipulated.
- ///
- /// This method performs the necessary conversion immediately, so it can be
- /// expensive to call. It is recommended to continue using the returned
- /// instance as long as possible (instead of the original [`OsStr`]), to
- /// avoid repeated conversions.
- ///
- /// # Nightly Notes
- ///
- /// This method is deprecated. Use [`from_os_str`] instead.
+ /// Wraps a platform-native string, without copying or encoding conversion.
///
/// # Examples
///
@@ -142,51 +130,14 @@ impl RawOsStr {
/// use os_str_bytes::RawOsStr;
///
/// let os_string = env::current_exe()?.into_os_string();
- /// println!("{:?}", RawOsStr::new(&os_string));
+ /// println!("{:?}", RawOsStr::from_os_str(&os_string));
/// #
/// # Ok::<_, io::Error>(())
/// ```
- ///
- /// [`from_os_str`]: Self::from_os_str
- #[cfg_attr(
- all(not(os_str_bytes_docs_rs), feature = "nightly"),
- deprecated(since = "6.6.0", note = "use `from_os_str` instead")
- )]
#[inline]
#[must_use]
- pub fn new(string: &OsStr) -> Cow<'_, Self> {
- if_nightly_return! {{
- Cow::Borrowed(Self::from_os_str(string))
- }}
- match imp::os_str_to_bytes(string) {
- Cow::Borrowed(string) => Cow::Borrowed(Self::from_inner(string)),
- Cow::Owned(string) => Cow::Owned(RawOsString(string)),
- }
- }
-
- if_nightly! {
- /// Wraps a platform-native string, without copying or encoding
- /// conversion.
- ///
- /// # Examples
- ///
- /// ```
- /// use std::env;
- /// # use std::io;
- ///
- /// use os_str_bytes::RawOsStr;
- ///
- /// let os_string = env::current_exe()?.into_os_string();
- /// println!("{:?}", RawOsStr::from_os_str(&os_string));
- /// #
- /// # Ok::<_, io::Error>(())
- /// ```
- #[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "nightly")))]
- #[inline]
- #[must_use]
- pub fn from_os_str(string: &OsStr) -> &Self {
- Self::from_inner(string.as_encoded_bytes())
- }
+ pub fn from_os_str(string: &OsStr) -> &Self {
+ Self::from_inner(string.as_encoded_bytes())
}
/// Wraps a string, without copying or encoding conversion.
@@ -212,48 +163,39 @@ impl RawOsStr {
Self::from_inner(string.as_bytes())
}
- if_nightly! {
- /// Equivalent to [`OsStr::from_encoded_bytes_unchecked`].
- ///
- /// # Examples
- ///
- /// ```
- /// use std::env;
- /// # use std::io;
- ///
- /// use os_str_bytes::RawOsStr;
- ///
- /// let os_string = env::current_exe()?.into_os_string();
- /// let raw = RawOsStr::from_os_str(&os_string);
- /// let raw_bytes = raw.as_encoded_bytes();
- /// assert_eq!(raw, unsafe {
- /// RawOsStr::from_encoded_bytes_unchecked(raw_bytes)
- /// });
- /// #
- /// # Ok::<_, io::Error>(())
- /// ```
- ///
- /// [unspecified encoding]: super#encoding
- #[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "nightly")))]
- #[inline]
- #[must_use]
- pub unsafe fn from_encoded_bytes_unchecked(string: &[u8]) -> &Self {
- Self::from_inner(string)
- }
+ /// Equivalent to [`OsStr::from_encoded_bytes_unchecked`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::env;
+ /// # use std::io;
+ ///
+ /// use os_str_bytes::RawOsStr;
+ ///
+ /// let os_string = env::current_exe()?.into_os_string();
+ /// let raw = RawOsStr::from_os_str(&os_string);
+ /// let raw_bytes = raw.as_encoded_bytes();
+ /// assert_eq!(raw, unsafe {
+ /// RawOsStr::from_encoded_bytes_unchecked(raw_bytes)
+ /// });
+ /// #
+ /// # Ok::<_, io::Error>(())
+ /// ```
+ ///
+ /// [unspecified encoding]: super#encoding
+ #[allow(clippy::missing_safety_doc)]
+ #[inline]
+ #[must_use]
+ pub unsafe fn from_encoded_bytes_unchecked(string: &[u8]) -> &Self {
+ Self::from_inner(string)
}
if_conversions! {
fn cow_from_raw_bytes_checked(
string: &[u8],
) -> imp::Result