One-character string used where a char pattern is faster

ID

rust.performance.single_char_pattern

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Inefficient Api Usage

Language

Rust

Description

Reports a string-search method given a string literal holding exactly one character, where a char literal expresses the same pattern.

Rationale

A &str pattern searches for a substring, so it runs the general string matcher and rescans on every partial hit. A char pattern compiles to a direct scan for one scalar value, which the standard library can vectorise. On hot paths - splitting every line of a file, trimming every key - the difference shows, and the char form also states that a single character is meant rather than a prefix that happens to be short today.

The following code illustrates the pattern detected by this rule:

pub fn fields(line: &str) -> Vec<&str> {
    // FLAGGED: One-character string used where a char pattern is faster
    line.split(",").collect()
}

Remediation

Change the double quotes to single quotes - line.split(",") becomes line.split(','). Escapes carry over unchanged ("\n" becomes '\n').

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved