Skip to content

Lint suggesting to replace str::bytes().count() with str::len() #8083

Closed
@wooster0

Description

@wooster0

What it does

It checks for str::bytes().count() and suggests replacing it with str::len() that does the same but shorter and possibly more performant.

Extra: can something like this be done for https://doc.rust-lang.org/std/io/trait.Read.html#method.bytes too?

Lint Name

bytes_count_to_len

Category

complexity

Advantage

  • Might be more performant
  • Shorter
  • Possibly easier to read

Drawbacks

No response

Example

fn main() {
    "hello".bytes().count();
}

Could be written as:

fn main() {
    "hello".len();
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions