diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5864cea..2a9a44d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: - run: rustup default ${{ matrix.version }} - run: rustup component add clippy - run: rustup target add ${{ matrix.target }} - - run: cargo clippy --all-features --target ${{ matrix.target }} -- -Dwarnings + - run: cargo clippy --target ${{ matrix.target }} -- -Dwarnings timeout-minutes: 5 strategy: matrix: @@ -49,7 +49,7 @@ jobs: - run: rustup default nightly - run: rustup target add ${{ matrix.target }} # Clippy might not be packaged with the current nightly compiler. - - run: cargo rustc --all-features --target ${{ matrix.target }} -- -Dwarnings + - run: cargo rustc --target ${{ matrix.target }} -- -Dwarnings timeout-minutes: 5 strategy: matrix: diff --git a/Cargo.toml b/Cargo.toml index a15092e..33a86e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,10 @@ all-features = true rustc-args = ["--cfg", "os_str_bytes_docs_rs"] rustdoc-args = ["--cfg", "os_str_bytes_docs_rs"] +[dependencies] +print_bytes = { version = "0.4", optional = true } +uniquote = { version = "2.0", optional = true } + [dev-dependencies] getrandom = { version = "0.2", features = ["js"] } diff --git a/src/lib.rs b/src/lib.rs index f5fcf43..c85126e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,9 +59,17 @@ //! //! ### Optional Features //! +//! - **print_bytes** - +//! Provides implementations of [`print_bytes::ToBytes`] for [`RawOsStr`] and +//! [`RawOsString`]. +//! //! - **raw_os_str** - //! Enables use of [`RawOsStr`] and [`RawOsString`]. //! +//! - **uniquote** - +//! Provides implementations of [`uniquote::Quote`] for [`RawOsStr`] and +//! [`RawOsString`]. +//! //! # Implementation //! //! Some methods return [`Cow`] to account for platform differences. However, diff --git a/src/raw_str.rs b/src/raw_str.rs index 1d92798..f7d0802 100644 --- a/src/raw_str.rs +++ b/src/raw_str.rs @@ -13,6 +13,14 @@ use super::pattern::Pattern; use super::OsStrBytes; use super::OsStringBytes; +#[cfg(feature = "print_bytes")] +use print_bytes::Bytes; +#[cfg(feature = "print_bytes")] +use print_bytes::ToBytes; + +#[cfg(feature = "uniquote")] +use uniquote::Quote; + fn find_pattern(string: &[u8], pat: &[u8]) -> Option { for i in 0..=string.len().checked_sub(pat.len())? { if string[i..].starts_with(pat) { @@ -702,6 +710,24 @@ impl<'a> From<&'a RawOsStr> for Cow<'a, RawOsStr> { } } +#[cfg(feature = "uniquote")] +#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "uniquote")))] +impl Quote for RawOsStr { + #[inline] + fn escape(&self, f: &mut uniquote::Formatter<'_>) -> uniquote::Result { + self.0.escape(f) + } +} + +#[cfg(feature = "print_bytes")] +#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))] +impl ToBytes for RawOsStr { + #[inline] + fn to_bytes(&self) -> Bytes<'_> { + self.0.to_bytes() + } +} + impl ToOwned for RawOsStr { type Owned = RawOsString; @@ -871,6 +897,24 @@ impl From for Cow<'_, RawOsStr> { } } +#[cfg(feature = "uniquote")] +#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "uniquote")))] +impl Quote for RawOsString { + #[inline] + fn escape(&self, f: &mut uniquote::Formatter<'_>) -> uniquote::Result { + (**self).escape(f) + } +} + +#[cfg(feature = "print_bytes")] +#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))] +impl ToBytes for RawOsString { + #[inline] + fn to_bytes(&self) -> Bytes<'_> { + (**self).to_bytes() + } +} + macro_rules! r#impl { ( $type:ty , $other_type:ty ) => { impl PartialEq<$other_type> for $type {