Skip to content

Commit

Permalink
Let compiler synthesize Equatable and Hashable conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
norio-nomura committed Jun 16, 2018
1 parent 4424585 commit 7f9eff9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Yams/Node.Mapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ private struct Pair<Value: Comparable & Equatable>: Comparable, Equatable {
self.value = value
}

#if !swift(>=4.1.50)
static func == (lhs: Pair, rhs: Pair) -> Bool {
return lhs.key == rhs.key && lhs.value == rhs.value
}
#endif

static func < (lhs: Pair<Value>, rhs: Pair<Value>) -> Bool {
return lhs.key < rhs.key
Expand Down
2 changes: 2 additions & 0 deletions Sources/Yams/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ extension Node {
// MARK: Hashable

extension Node: Hashable {
#if !swift(>=4.1.50)
/// This `Node`'s Hashable `hashValue`.
public var hashValue: Int {
switch self {
Expand Down Expand Up @@ -216,6 +217,7 @@ extension Node: Hashable {
return false
}
}
#endif
}

// MARK: Comparable
Expand Down
2 changes: 2 additions & 0 deletions Sources/Yams/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extension Tag.Name: ExpressibleByStringLiteral {
}

extension Tag.Name: Hashable {
#if !swift(>=4.1.50)
/// :nodoc:
public var hashValue: Int {
return rawValue.hashValue
Expand All @@ -114,6 +115,7 @@ extension Tag.Name: Hashable {
public static func == (lhs: Tag.Name, rhs: Tag.Name) -> Bool {
return lhs.rawValue == rhs.rawValue
}
#endif
}

// http://www.yaml.org/spec/1.2/spec.html#Schema
Expand Down

0 comments on commit 7f9eff9

Please sign in to comment.