Skip to content

HashMap using &str keys is not a a realistic example #46966

Closed
@kornelski

Description

@kornelski

The example in the docs uses HashMap of &str:

https://doc.rust-lang.org/std/collections/struct.HashMap.html#examples

but this gives bad example to users who copy the example without fully realizing consequences of using &str instead of String. Here's thread by a new user lead down a confusing path because of this example: https://users.rust-lang.org/t/how-to-pass-slice-of-structs-string-field/14586

I suggest using String instead, even if that means a bit more noise from to_owned().

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions