diff --git a/Sources/Pool.swift b/Sources/Pool.swift index c32435a..186e469 100644 --- a/Sources/Pool.swift +++ b/Sources/Pool.swift @@ -64,6 +64,7 @@ public final class Pool { } } +// WORKAROUND: #2 Swift doesn't support same-type requirements on generics private protocol _ByIdentityProtocol: Hashable { associatedtype Object: AnyObject init(_ object: Object) @@ -76,6 +77,7 @@ private struct ByIdentity { } } +// 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) @@ -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 { diff --git a/Sources/SQLConnection.swift b/Sources/SQLConnection.swift index 6081838..ab24934 100644 --- a/Sources/SQLConnection.swift +++ b/Sources/SQLConnection.swift @@ -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: _SQLConnection where C.RowStateSequence.Iterator.Element == C.RowState { public typealias Client = C public var state: Client.ConnectionState diff --git a/Sources/SQLDatabase.swift b/Sources/SQLDatabase.swift index c24d14f..6c5538c 100644 --- a/Sources/SQLDatabase.swift +++ b/Sources/SQLDatabase.swift @@ -47,6 +47,7 @@ public struct SQLDatabase 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. ///