Skip to content

Unnecessary Use of ToString Trait Bounds on Parameters #6

@Imran-imtiaz48

Description

@Imran-imtiaz48

Each function uses T: ToString as a trait bound for its parameter, which is more general than needed and can lead to unexpected behavior or performance issues. Most likely, these functions are only intended to work with string-like types, such as &str or String.

Using impl Into instead of T: ToString is often preferred for constructors expecting ownership because it is more idiomatic and flexible in Rust, especially for APIs consuming strings. Alternatively, using &str directly could avoid unnecessary allocations if ownership isn't required.

For example, change:

pub fn column<T: ToString>(name: T) -> Column {

to:

pub fn column(name: impl Into) -> Column {

This change improves readability, idiomatic usage, and type inference without sacrificing flexibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions