Skip to content

Commit 418c2cd

Browse files
burtonageoThomas Bahn
authored and
Thomas Bahn
committed
Refactor various methods to use iterators
1 parent 85fd943 commit 418c2cd

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/ascii_str.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl AsciiStr {
189189
/// assert_eq!("white \tspace \t", example.trim_left());
190190
/// ```
191191
pub fn trim_left(&self) -> &Self {
192-
&self[self.slice.iter().take_while(|a| a.is_whitespace()).count()..]
192+
&self[self.chars().take_while(|a| a.is_whitespace()).count()..]
193193
}
194194

195195
/// Returns an ASCII string slice with trailing whitespace removed.
@@ -201,8 +201,7 @@ impl AsciiStr {
201201
/// assert_eq!(" \twhite \tspace", example.trim_right());
202202
/// ```
203203
pub fn trim_right(&self) -> &Self {
204-
let trimmed = self.slice
205-
.into_iter()
204+
let trimmed = self.chars()
206205
.rev()
207206
.take_while(|a| a.is_whitespace())
208207
.count();
@@ -215,7 +214,7 @@ impl AsciiStr {
215214
#[cfg(not(feature = "std"))]
216215
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {
217216
self.len() == other.len() &&
218-
self.slice.iter().zip(other.slice.iter()).all(|(a, b)| {
217+
self.chars().zip(other.chars()).all(|(a, b)| {
219218
a.eq_ignore_ascii_case(b)
220219
})
221220
}
@@ -225,7 +224,7 @@ impl AsciiStr {
225224
/// A replacement for `AsciiExt::make_ascii_uppercase()`.
226225
#[cfg(not(feature = "std"))]
227226
pub fn make_ascii_uppercase(&mut self) {
228-
for a in &mut self.slice {
227+
for a in &mut self {
229228
*a = a.to_ascii_uppercase();
230229
}
231230
}
@@ -235,7 +234,7 @@ impl AsciiStr {
235234
/// A replacement for `AsciiExt::make_ascii_lowercase()`.
236235
#[cfg(not(feature = "std"))]
237236
pub fn make_ascii_lowercase(&mut self) {
238-
for a in &mut self.slice {
237+
for a in &mut self {
239238
*a = a.to_ascii_lowercase();
240239
}
241240
}

src/ascii_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl AsciiString {
146146
/// ```
147147
#[inline]
148148
pub fn push_str(&mut self, string: &AsciiStr) {
149-
self.vec.extend(string.as_slice().iter().cloned())
149+
self.vec.extend(string.chars().cloned())
150150
}
151151

152152
/// Returns the number of bytes that this ASCII string buffer can hold without reallocating.

0 commit comments

Comments
 (0)