From ec388f9160769610a6072aef56cc2f7481ae665b Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Mon, 23 Dec 2024 12:38:37 +0100 Subject: [PATCH] Use synthesized Equatable & Hashable --- AutomergeUniffi/automerge.swift | 132 +------------------ Sources/Automerge/Codable/BindingError.swift | 3 - 2 files changed, 6 insertions(+), 129 deletions(-) diff --git a/AutomergeUniffi/automerge.swift b/AutomergeUniffi/automerge.swift index 84c1c736..406afa58 100644 --- a/AutomergeUniffi/automerge.swift +++ b/AutomergeUniffi/automerge.swift @@ -1487,7 +1487,7 @@ public func FfiConverterTypeSyncState_lower(_ value: SyncState) -> UnsafeMutable } -public struct Change { +public struct Change: Equatable, Hashable { public var actorId: ActorId public var message: String? public var deps: [ChangeHash] @@ -1508,41 +1508,6 @@ public struct Change { } - -extension Change: Equatable, Hashable { - public static func ==(lhs: Change, rhs: Change) -> Bool { - if lhs.actorId != rhs.actorId { - return false - } - if lhs.message != rhs.message { - return false - } - if lhs.deps != rhs.deps { - return false - } - if lhs.timestamp != rhs.timestamp { - return false - } - if lhs.bytes != rhs.bytes { - return false - } - if lhs.hash != rhs.hash { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(actorId) - hasher.combine(message) - hasher.combine(deps) - hasher.combine(timestamp) - hasher.combine(bytes) - hasher.combine(hash) - } -} - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1585,7 +1550,7 @@ public func FfiConverterTypeChange_lower(_ value: Change) -> RustBuffer { } -public struct KeyValue { +public struct KeyValue: Equatable, Hashable { public var key: String public var value: Value @@ -1598,25 +1563,6 @@ public struct KeyValue { } - -extension KeyValue: Equatable, Hashable { - public static func ==(lhs: KeyValue, rhs: KeyValue) -> Bool { - if lhs.key != rhs.key { - return false - } - if lhs.value != rhs.value { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(key) - hasher.combine(value) - } -} - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1651,7 +1597,7 @@ public func FfiConverterTypeKeyValue_lower(_ value: KeyValue) -> RustBuffer { } -public struct Mark { +public struct Mark: Equatable, Hashable { public var start: UInt64 public var end: UInt64 public var name: String @@ -1668,33 +1614,6 @@ public struct Mark { } - -extension Mark: Equatable, Hashable { - public static func ==(lhs: Mark, rhs: Mark) -> Bool { - if lhs.start != rhs.start { - return false - } - if lhs.end != rhs.end { - return false - } - if lhs.name != rhs.name { - return false - } - if lhs.value != rhs.value { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(start) - hasher.combine(end) - hasher.combine(name) - hasher.combine(value) - } -} - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1733,7 +1652,7 @@ public func FfiConverterTypeMark_lower(_ value: Mark) -> RustBuffer { } -public struct Patch { +public struct Patch: Equatable, Hashable { public var path: [PathElement] public var action: PatchAction @@ -1745,26 +1664,6 @@ public struct Patch { } } - - -extension Patch: Equatable, Hashable { - public static func ==(lhs: Patch, rhs: Patch) -> Bool { - if lhs.path != rhs.path { - return false - } - if lhs.action != rhs.action { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(path) - hasher.combine(action) - } -} - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1799,7 +1698,7 @@ public func FfiConverterTypePatch_lower(_ value: Patch) -> RustBuffer { } -public struct PathElement { +public struct PathElement: Equatable, Hashable { public var prop: Prop public var obj: ObjId @@ -1812,25 +1711,6 @@ public struct PathElement { } - -extension PathElement: Equatable, Hashable { - public static func ==(lhs: PathElement, rhs: PathElement) -> Bool { - if lhs.prop != rhs.prop { - return false - } - if lhs.obj != rhs.obj { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(prop) - hasher.combine(obj) - } -} - - #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -3548,4 +3428,4 @@ private func uniffiEnsureInitialized() { } } -// swiftlint:enable all \ No newline at end of file +// swiftlint:enable all diff --git a/Sources/Automerge/Codable/BindingError.swift b/Sources/Automerge/Codable/BindingError.swift index 47f8d22b..838775e2 100644 --- a/Sources/Automerge/Codable/BindingError.swift +++ b/Sources/Automerge/Codable/BindingError.swift @@ -2,9 +2,6 @@ import Foundation /// Binding errors public enum BindingError: LocalizedError, Equatable { - public static func == (lhs: BindingError, rhs: BindingError) -> Bool { - lhs.errorDescription == rhs.errorDescription - } /// The path provided was invalid to bind into the Automerge document. case InvalidPath(String)