RS.CLIPPY.BYTES_COUNT_TO_LEN

Using `bytes().count()` when `len()` performs the same functionality

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: bytes_count_to_len. Copyright ©2025 The Rust Team. All rights reserved.

What it does

It checks for str::bytes().count() and suggests replacing it with str::len().

Why is this bad?

str::bytes().count() is longer and may not be as performant as using str::len().

Example

"hello".bytes().count();
String::from("hello").bytes().count();

Use instead:

"hello".len();
String::from("hello").len();