diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/hashes.nim | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim index 3cf0a8f82..54e083d25 100644 --- a/lib/pure/hashes.nim +++ b/lib/pure/hashes.nim @@ -54,6 +54,20 @@ runnableExamples: ## **Note:** If the type has a `==` operator, the following must hold: ## If two values compare equal, their hashes must also be equal. ## +## You can hash an object by all of its fields with the `fields` iterator: +runnableExamples: + proc hash(x: object): Hash = + for f in fields(x): + result = result !& hash(f) + result = !$result + + type + Obj = object + x: int + y: string + + doAssert hash(Obj(x: 520, y: "Nim")) != hash(Obj(x: 520, y: "Nim2")) + ## See also ## ======== ## * `md5 module <md5.html>`_ for the MD5 checksum algorithm |