Skip to content

Commit 1fe18fc

Browse files
Added more sendable conformances
1 parent d896503 commit 1fe18fc

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Sources/CodableDatastore/Datastore/Datastore.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,10 @@ extension Datastore {
585585
/// - index: The index to load from.
586586
/// - Returns: An asynchronous sequence containing the instances matching the range of values in that sequence.
587587
@usableFromInline
588-
nonisolated func _load<Index: IndexRepresentation<InstanceType> & Sendable, Bound: Indexable & Sendable>(
588+
nonisolated func _load<
589+
Index: IndexRepresentation<InstanceType>,
590+
Bound: Indexable
591+
>(
589592
_ range: some IndexRangeExpression<Bound> & Sendable,
590593
order: RangeOrder = .ascending,
591594
from index: KeyPath<Format, Index>
@@ -652,7 +655,7 @@ extension Datastore {
652655
Value: DiscreteIndexable,
653656
Index: RetrievableIndexRepresentation<InstanceType, Value>
654657
>(
655-
_ value: Index.Value,
658+
_ value: Value,
656659
order: RangeOrder = .ascending,
657660
from index: KeyPath<Format, Index>
658661
) -> some TypedAsyncSequence<InstanceType> & Sendable {
@@ -667,10 +670,10 @@ extension Datastore {
667670
/// - index: The index to load from.
668671
/// - Returns: The instance keyed to the specified indexed value, or nil if none are found.
669672
public nonisolated func load<
670-
Value,
673+
Value: DiscreteIndexable,
671674
Index: SingleInstanceIndexRepresentation<InstanceType, Value>
672675
>(
673-
_ value: Index.Value,
676+
_ value: Value,
674677
from index: KeyPath<Format, Index>
675678
) async throws -> InstanceType? {
676679
try await _load(IndexRange(only: value), from: index).first(where: { _ in true })

Sources/CodableDatastore/Indexes/IndexRepresentation.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public protocol MultipleInputIndexRepresentation<
6767
Value
6868
>: RetrievableIndexRepresentation {
6969
/// The sequence of values represented in the index.
70-
associatedtype Sequence: Swift.Sequence<Value>
70+
associatedtype Sequence: Swift.Sequence<Value> & Sendable
7171
}
7272

7373
/// An index where every value matches at most a single instance.
@@ -76,7 +76,7 @@ public protocol MultipleInputIndexRepresentation<
7676
public struct OneToOneIndexRepresentation<
7777
Instance: Sendable,
7878
Value: Indexable & DiscreteIndexable
79-
>: SingleInstanceIndexRepresentation, @unchecked Sendable {
79+
>: SingleInstanceIndexRepresentation {
8080
@usableFromInline
8181
let keypath: KeyPath<Instance, Value>
8282

@@ -109,7 +109,7 @@ public struct OneToOneIndexRepresentation<
109109
public struct OneToManyIndexRepresentation<
110110
Instance: Sendable,
111111
Value: Indexable
112-
>: RetrievableIndexRepresentation, @unchecked Sendable {
112+
>: RetrievableIndexRepresentation {
113113
@usableFromInline
114114
let keypath: KeyPath<Instance, Value>
115115

@@ -142,9 +142,9 @@ public struct OneToManyIndexRepresentation<
142142
/// This type of index can be used if several alternative identifiers can reference an instance, and they all reside in a single property.
143143
public struct ManyToOneIndexRepresentation<
144144
Instance: Sendable,
145-
Sequence: Swift.Sequence<Value>,
145+
Sequence: Swift.Sequence<Value> & Sendable,
146146
Value: Indexable & DiscreteIndexable
147-
>: SingleInstanceIndexRepresentation & MultipleInputIndexRepresentation, @unchecked Sendable {
147+
>: SingleInstanceIndexRepresentation & MultipleInputIndexRepresentation {
148148
@usableFromInline
149149
let keypath: KeyPath<Instance, Sequence>
150150

@@ -177,9 +177,9 @@ public struct ManyToOneIndexRepresentation<
177177
/// This type of index is common when building relationships between different instances, where one instance may be related to several others in some way.
178178
public struct ManyToManyIndexRepresentation<
179179
Instance: Sendable,
180-
Sequence: Swift.Sequence<Value>,
180+
Sequence: Swift.Sequence<Value> & Sendable,
181181
Value: Indexable
182-
>: MultipleInputIndexRepresentation, @unchecked Sendable {
182+
>: MultipleInputIndexRepresentation {
183183
@usableFromInline
184184
let keypath: KeyPath<Instance, Sequence>
185185

@@ -274,3 +274,6 @@ public struct AnyIndexRepresentation<Instance: Sendable>: Hashable, Sendable {
274274
hasher.combine(indexRepresentation)
275275
}
276276
}
277+
278+
/// Forced KeyPath conformance since Swift 5.10 doesn't support it out of the box.
279+
extension KeyPath: @unchecked Sendable where Root: Sendable, Value: Sendable {}

0 commit comments

Comments
 (0)