From 20b8480c0bdd35e8a466bf2554d9d1f9347c7ef2 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Fri, 8 Mar 2019 18:45:42 +0100 Subject: [PATCH] Make Document hashable --- Sources/BSON/Document/Document+Equatable.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/BSON/Document/Document+Equatable.swift b/Sources/BSON/Document/Document+Equatable.swift index c44c11a..4308490 100644 --- a/Sources/BSON/Document/Document+Equatable.swift +++ b/Sources/BSON/Document/Document+Equatable.swift @@ -3,3 +3,11 @@ extension Document: Equatable { return lhs.makeData() == rhs.makeData() } } + +extension Document: Hashable { + public func hash(into hasher: inout Hasher) { + self.makeByteBuffer().withUnsafeReadableBytes { buffer in + hasher.combine(bytes: buffer) + } + } +}