Skip to content

Commit c6dc9ff

Browse files
committed
Minor improvements
1 parent 2774466 commit c6dc9ff

File tree

4 files changed

+61
-57
lines changed

4 files changed

+61
-57
lines changed

src/common/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(crate) const fn is_continuation(_: u8) -> bool {
88

99
#[inline(always)]
1010
pub(crate) fn decode_code_point(_: &[u8]) -> u32 {
11-
unreachable!()
11+
unreachable!();
1212
}
1313

1414
pub(crate) fn ends_with(string: &[u8], suffix: &[u8]) -> bool {

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@
6868
//!
6969
//! - **memchr** -
7070
//! Changes the implementation to use crate [memchr] for better performance.
71-
//! This feature is useless when "raw_os_str" is disabled.
71+
//! This feature is useless when "raw\_os\_str" is disabled.
7272
//!
7373
//! For more information, see [`RawOsStr`][memchr complexity].
7474
//!
75-
//! - **raw_os_str** -
75+
//! - **raw\_os\_str** -
7676
//! Enables use of [`RawOsStr`] and [`RawOsString`].
7777
//!
7878
//! ### Optional Features
7979
//!
80-
//! - **print_bytes** -
80+
//! - **print\_bytes** -
8181
//! Provides implementations of [`print_bytes::ToBytes`] for [`RawOsStr`] and
8282
//! [`RawOsString`].
8383
//!

src/raw_str.rs

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,18 @@ use std::ops::RangeTo;
1818
use std::ops::RangeToInclusive;
1919
use std::str;
2020

21+
#[cfg(feature = "memchr")]
22+
use memchr::memmem::find;
23+
#[cfg(feature = "memchr")]
24+
use memchr::memmem::rfind;
25+
2126
use super::imp::raw;
2227
use super::iter::Split;
2328
use super::pattern::Encoded as EncodedPattern;
2429
use super::OsStrBytes;
2530
use super::OsStringBytes;
2631
use super::Pattern;
2732

28-
#[cfg(feature = "memchr")]
29-
use memchr::memmem::find;
30-
#[cfg(feature = "memchr")]
31-
use memchr::memmem::rfind;
32-
33-
#[cfg(feature = "print_bytes")]
34-
use print_bytes::Bytes;
35-
#[cfg(feature = "print_bytes")]
36-
use print_bytes::ToBytes;
37-
38-
#[cfg(feature = "uniquote")]
39-
use uniquote::Quote;
40-
4133
#[cfg(not(feature = "memchr"))]
4234
fn find(string: &[u8], pat: &[u8]) -> Option<usize> {
4335
for i in 0..=string.len().checked_sub(pat.len())? {
@@ -67,9 +59,6 @@ macro_rules! impl_trim_matches {
6759
}
6860

6961
let mut string = &$self.0;
70-
#[allow(unused_mut)]
71-
#[allow(unused_variables)]
72-
let mut matches = 0;
7362
while let Some(substring) = string.$strip_method(pat) {
7463
string = substring;
7564
}
@@ -826,24 +815,6 @@ r#impl!(RangeInclusive<usize>, x, *x.start(), x.end().wrapping_add(1));
826815
r#impl!(RangeTo<usize>, x, x.end);
827816
r#impl!(RangeToInclusive<usize>, x, x.end.wrapping_add(1));
828817

829-
#[cfg(feature = "uniquote")]
830-
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "uniquote")))]
831-
impl Quote for RawOsStr {
832-
#[inline]
833-
fn escape(&self, f: &mut uniquote::Formatter<'_>) -> uniquote::Result {
834-
self.0.escape(f)
835-
}
836-
}
837-
838-
#[cfg(feature = "print_bytes")]
839-
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))]
840-
impl ToBytes for RawOsStr {
841-
#[inline]
842-
fn to_bytes(&self) -> Bytes<'_> {
843-
self.0.to_bytes()
844-
}
845-
}
846-
847818
impl ToOwned for RawOsStr {
848819
type Owned = RawOsString;
849820

@@ -1030,24 +1001,6 @@ r#impl!(RangeInclusive<usize>);
10301001
r#impl!(RangeTo<usize>);
10311002
r#impl!(RangeToInclusive<usize>);
10321003

1033-
#[cfg(feature = "uniquote")]
1034-
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "uniquote")))]
1035-
impl Quote for RawOsString {
1036-
#[inline]
1037-
fn escape(&self, f: &mut uniquote::Formatter<'_>) -> uniquote::Result {
1038-
(**self).escape(f)
1039-
}
1040-
}
1041-
1042-
#[cfg(feature = "print_bytes")]
1043-
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))]
1044-
impl ToBytes for RawOsString {
1045-
#[inline]
1046-
fn to_bytes(&self) -> Bytes<'_> {
1047-
(**self).to_bytes()
1048-
}
1049-
}
1050-
10511004
struct Buffer<'a>(&'a [u8]);
10521005

10531006
impl Debug for Buffer<'_> {
@@ -1132,3 +1085,52 @@ r#impl!(&RawOsStr, String);
11321085
r#impl!(RawOsString, str);
11331086
r#impl!(RawOsString, &str);
11341087
r#impl!(RawOsString, String);
1088+
1089+
#[cfg(feature = "print_bytes")]
1090+
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "print_bytes")))]
1091+
mod print_bytes {
1092+
use print_bytes::Bytes;
1093+
use print_bytes::ToBytes;
1094+
1095+
use super::RawOsStr;
1096+
use super::RawOsString;
1097+
1098+
impl ToBytes for RawOsStr {
1099+
#[inline]
1100+
fn to_bytes(&self) -> Bytes<'_> {
1101+
self.0.to_bytes()
1102+
}
1103+
}
1104+
1105+
impl ToBytes for RawOsString {
1106+
#[inline]
1107+
fn to_bytes(&self) -> Bytes<'_> {
1108+
(**self).to_bytes()
1109+
}
1110+
}
1111+
}
1112+
1113+
#[cfg(feature = "uniquote")]
1114+
#[cfg_attr(os_str_bytes_docs_rs, doc(cfg(feature = "uniquote")))]
1115+
mod uniquote {
1116+
use uniquote::Formatter;
1117+
use uniquote::Quote;
1118+
use uniquote::Result;
1119+
1120+
use super::RawOsStr;
1121+
use super::RawOsString;
1122+
1123+
impl Quote for RawOsStr {
1124+
#[inline]
1125+
fn escape(&self, f: &mut Formatter<'_>) -> Result {
1126+
self.0.escape(f)
1127+
}
1128+
}
1129+
1130+
impl Quote for RawOsString {
1131+
#[inline]
1132+
fn escape(&self, f: &mut Formatter<'_>) -> Result {
1133+
(**self).escape(f)
1134+
}
1135+
}
1136+
}

src/wasm32/raw.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ pub(crate) use crate::util::is_continuation;
77
pub(crate) fn decode_code_point(string: &[u8]) -> u32 {
88
let string = str::from_utf8(string).expect("invalid string");
99
let mut chs = string.chars();
10-
let ch = chs.next().expect("cannot parse code point from empty string");
10+
let ch = chs
11+
.next()
12+
.expect("cannot parse code point from empty string");
1113
assert_eq!(None, chs.next(), "multiple code points found");
1214
ch.into()
1315
}

0 commit comments

Comments
 (0)