Implement traits from other crates

This commit is contained in:
dylni
2021-08-15 18:52:11 -04:00
parent 0ededea0b5
commit f436c4b901
4 changed files with 58 additions and 2 deletions
+2 -2
View File
@@ -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:
+4
View File
@@ -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"] }
+8
View File
@@ -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,
+44
View File
@@ -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<usize> {
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<RawOsString> 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 {