Closed taywrobel closed 7 years ago
Objects do not return their own types but stdlib's hash.Hash32
and hash.Hash64
(unless you're referring to Hash128 for which there’s no stdlib equivalent).
hash.Hash
is a subset of those more specialized hash.Hash32
and hash.Hash64
interfaces.
Producers would indeed process data through hash.Hash
, while some endpoints might prefer e.g hash.Hash64
.
All stdlib's hash constructors use the same approach (e.g Adler, FNV). Is there any specific usage you’re still having issues with?
The way that the hash functions are implemented - containing the hash.Hash instance, and the constructor, doesn't allow for them to be used in place of standard hash.Hash implementations.
I.e. if a program is designed to have swappable hash implementations, they will commonly take as a parameter of type (hashFunc func() hash.Hash)
However, since the objects return their own types - Hash32, Hash64 or Hash128, the New functions do not have a matching signature, and cannot be easily used in place of the other hash functions.