Skip to content

Commit 2653c3c

Browse files
committed
Do not use .as_bytes().len() on strings
1 parent 4e4b657 commit 2653c3c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

exercises/23_conversions/as_ref_mut.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
33
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
44

5-
// Obtain the number of bytes (not characters) in the given argument.
5+
// Obtain the number of bytes (not characters) in the given argument
6+
// (`.len()` returns the number of bytes in a string).
67
// TODO: Add the `AsRef` trait appropriately as a trait bound.
78
fn byte_counter<T>(arg: T) -> usize {
8-
arg.as_ref().as_bytes().len()
9+
arg.as_ref().len()
910
}
1011

1112
// Obtain the number of characters (not bytes) in the given argument.

solutions/23_conversions/as_ref_mut.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
33
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
44

5-
// Obtain the number of bytes (not characters) in the given argument.
5+
// Obtain the number of bytes (not characters) in the given argument
6+
// (`.len()` returns the number of bytes in a string).
67
fn byte_counter<T: AsRef<str>>(arg: T) -> usize {
7-
arg.as_ref().as_bytes().len()
8+
arg.as_ref().len()
89
}
910

1011
// Obtain the number of characters (not bytes) in the given argument.

0 commit comments

Comments
 (0)