Skip to content

std::hash docs may lead to confusion #40498

Closed
@projektir

Description

@projektir

https://doc.rust-lang.org/std/hash/

The example given tries to demonstrate the use of a SipHasher as well as its hash() function. But in doing so, it also creates a new function to display the resulting hash, and this new function is also called hash(). The new function returns a value, while the library hash() function does not.

Since many people expect a hash function to return a value, some confusion may occur due to the example function being named exactly the same as the built-in function while being used to do something many may expect (returning a value). This actually came up on IRC.

I suggest the function in the example should be called something other than hash(), maybe get_hash().

[alternatively, should the built-in function be called hash, since it's just collecting values and the hashing is done upon finish()?]

Another thing: SipHasher appears to be deprecated for direct use. Perhaps this example should use DefaultHasher instead? May be related to #29357.

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions