Skip to content

proposal: hash: all implementations of Hash should implement io.StringWriter #54379

@dsnet

Description

@dsnet

In many situations, we have a string on hand rather than a []byte and we want to write that string into a hash.Hash.
Converting to []byte to call hash.Hash.Write is unfortunate since it allocates.

I propose that all (or most) implementations of hash.Hash also implement io.StringWriter. This would not require any changes to the hash.Hash interface (which can't change for compatibility reasons), but would allow anyone calling io.WriteString(h, s) to automatically benefit from allocation-free hashing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions