summaryrefslogtreecommitdiff
path: root/solutions
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2024-09-22 10:48:14 +0200
committerSamuel Tardieu <sam@rfc1149.net>2024-09-22 10:49:55 +0200
commit2653c3c4d448e4c3b0def82597796fa749f6f373 (patch)
treed780050d7da39965e86ab996817368a64d757660 /solutions
parent4e4b65711a20ae3d02baa79d8295da2b30ec7dd2 (diff)
Do not use `.as_bytes().len()` on strings
Diffstat (limited to 'solutions')
-rw-r--r--solutions/23_conversions/as_ref_mut.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/solutions/23_conversions/as_ref_mut.rs b/solutions/23_conversions/as_ref_mut.rs
index af62e2d..a5d2d4f 100644
--- a/solutions/23_conversions/as_ref_mut.rs
+++ b/solutions/23_conversions/as_ref_mut.rs
@@ -2,9 +2,10 @@
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
-// Obtain the number of bytes (not characters) in the given argument.
+// Obtain the number of bytes (not characters) in the given argument
+// (`.len()` returns the number of bytes in a string).
fn byte_counter<T: AsRef<str>>(arg: T) -> usize {
- arg.as_ref().as_bytes().len()
+ arg.as_ref().len()
}
// Obtain the number of characters (not bytes) in the given argument.