Created
October 17, 2022 08:57
-
-
Save karambirov/7824a453686e329dd7927d5656a4b624 to your computer and use it in GitHub Desktop.
Allows to ignore properties that prevent auto-conforming to Hashable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let hashableId = UUID() | |
@propertyWrapper | |
public struct IgnoreHashable<T>: Hashable { | |
public let wrappedValue: T | |
public init(wrappedValue: T) { | |
if wrappedValue is AnyHashable { | |
AssertionFailure("Hashable types shouldn't ignore its hash value") | |
} | |
self.wrappedValue = wrappedValue | |
} | |
public func hash(into hasher: inout Hasher) { | |
hasher.combine(hashableId) | |
} | |
public static func == (lhs: Self, rhs: Self) -> Bool { | |
return true | |
} | |
} | |
@propertyWrapper | |
public struct IgnoreEquatable<T>: Equatable { | |
public let wrappedValue: T | |
public init(wrappedValue: T) { | |
self.wrappedValue = wrappedValue | |
} | |
public static func == (lhs: Self, rhs: Self) -> Bool { | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment