Skip to content

Commit

Permalink
Add comments marking workarounds for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
beccadax committed Nov 1, 2016
1 parent 25ab475 commit 586aae8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Sources/Pool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public final class Pool<Resource: AnyObject> {
}
}

// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
private protocol _ByIdentityProtocol: Hashable {
associatedtype Object: AnyObject
init(_ object: Object)
Expand All @@ -76,6 +77,7 @@ private struct ByIdentity<Object: AnyObject> {
}
}

// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
extension ByIdentity: Hashable, _ByIdentityProtocol {
static func == (lhs: ByIdentity, rhs: ByIdentity) -> Bool {
return ObjectIdentifier(lhs.object) == ObjectIdentifier(rhs.object)
Expand All @@ -86,6 +88,7 @@ extension ByIdentity: Hashable, _ByIdentityProtocol {
}
}

// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
extension Dictionary where Key: _ByIdentityProtocol {
subscript(key: Key.Object) -> Value? {
get {
Expand Down
3 changes: 3 additions & 0 deletions Sources/SQLConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

import Foundation

/// Implementation detail used to detect SQLConnections in generics. Do not use.
// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
public protocol _SQLConnection {
associatedtype Client: SQLClient
}

// WORKAROUND: #1 Swift doesn't support `where` clauses on associated types
// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
public final class SQLConnection<C: SQLClient>: _SQLConnection where C.RowStateSequence.Iterator.Element == C.RowState {
public typealias Client = C
public var state: Client.ConnectionState
Expand Down
1 change: 1 addition & 0 deletions Sources/SQLDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public struct SQLDatabase<Client: SQLClient> where Client.RowStateSequence.Itera
}
}

// WORKAROUND: #2 Swift doesn't support same-type requirements on generics
extension Pool where Resource: _SQLConnection, Resource.Client.RowStateSequence.Iterator.Element == Resource.Client.RowState {
/// Creates a pool of connections to the given database.
///
Expand Down

0 comments on commit 586aae8

Please sign in to comment.