Skip to content

Commit 3621295

Browse files
committed
convert top level types to struct to make Sendable
1 parent 45154f9 commit 3621295

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Sources/KeyValueDecoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import CoreFoundation
3333
import Foundation
3434

3535
/// Top level encoder that converts `[String: Any]`, `[Any]` or `Any` into `Codable` types.
36-
public final class KeyValueDecoder {
36+
public struct KeyValueDecoder: Sendable {
3737

3838
/// Contextual user-provided information for use during encoding.
3939
public var userInfo: [CodingUserInfoKey: any Sendable]
@@ -94,7 +94,7 @@ extension KeyValueDecoder: TopLevelDecoder {
9494
extension KeyValueDecoder {
9595

9696
static func makePlistCompatible() -> KeyValueDecoder {
97-
let decoder = KeyValueDecoder()
97+
var decoder = KeyValueDecoder()
9898
decoder.nilDecodingStrategy = .stringNull
9999
return decoder
100100
}

Sources/KeyValueEncoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import Foundation
3333

3434
/// Top level encoder that converts `Codable` instances into loosely typed `[String: Any]`, `[Any]` or `Any`.
35-
public final class KeyValueEncoder {
35+
public struct KeyValueEncoder: Sendable {
3636

3737
/// Contextual user-provided information for use during encoding.
3838
public var userInfo: [CodingUserInfoKey: any Sendable]
@@ -85,7 +85,7 @@ extension KeyValueEncoder: TopLevelEncoder {
8585
extension KeyValueEncoder {
8686

8787
static func makePlistCompatible() -> KeyValueEncoder {
88-
let encoder = KeyValueEncoder()
88+
var encoder = KeyValueEncoder()
8989
encoder.nilEncodingStrategy = .stringNull
9090
return encoder
9191
}

Tests/KeyValueDecoderTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct KeyValueDecoderTests {
146146

147147
@Test
148148
func decodesRounded_Ints() throws {
149-
let decoder = KeyValueDecoder()
149+
var decoder = KeyValueDecoder()
150150
decoder.intDecodingStrategy = .rounding(rule: .toNearestOrAwayFromZero)
151151

152152
#expect(
@@ -235,7 +235,7 @@ struct KeyValueDecoderTests {
235235

236236
@Test
237237
func decodesRounded_UInts() throws {
238-
let decoder = KeyValueDecoder()
238+
var decoder = KeyValueDecoder()
239239
decoder.intDecodingStrategy = .rounding(rule: .toNearestOrAwayFromZero)
240240

241241
#expect(
@@ -422,7 +422,7 @@ struct KeyValueDecoderTests {
422422

423423
@Test
424424
func decodes_Null() throws {
425-
let decoder = KeyValueDecoder()
425+
var decoder = KeyValueDecoder()
426426
decoder.nilDecodingStrategy = .default
427427

428428
#expect(throws: (any Error).self) {
@@ -461,7 +461,7 @@ struct KeyValueDecoderTests {
461461

462462
@Test
463463
func decodes_UnkeyedOptionals() throws {
464-
let decoder = KeyValueDecoder()
464+
var decoder = KeyValueDecoder()
465465

466466
decoder.nilDecodingStrategy = .removed
467467
#expect(
@@ -704,7 +704,7 @@ struct KeyValueDecoderTests {
704704

705705
@Test
706706
func decodes_UnkeyedNil() throws {
707-
let decoder = KeyValueDecoder()
707+
var decoder = KeyValueDecoder()
708708
decoder.nilDecodingStrategy = .default
709709

710710
#expect(
@@ -917,7 +917,7 @@ struct KeyValueDecoderTests {
917917
UInt8(from: Double.nan, using: .clamping(roundingRule: nil)) == nil
918918
)
919919

920-
let decoder = KeyValueDecoder()
920+
var decoder = KeyValueDecoder()
921921
decoder.intDecodingStrategy = .clamping(roundingRule: .toNearestOrAwayFromZero)
922922
#expect(
923923
try decoder.decode([Int8].self, from: [10, 20.5, 1000, -Double.infinity]) == [
@@ -1004,7 +1004,7 @@ private extension KeyValueDecoder {
10041004
return try closure(&container)
10051005
}
10061006

1007-
let decoder = KeyValueDecoder()
1007+
var decoder = KeyValueDecoder()
10081008
decoder.userInfo[.decoder] = proxy as any DecodingProxy
10091009
_ = try decoder.decode(StubDecoder.self, from: value)
10101010
return proxy.result!
@@ -1019,14 +1019,14 @@ private extension KeyValueDecoder {
10191019
return try closure(&container)
10201020
}
10211021

1022-
let decoder = KeyValueDecoder()
1022+
var decoder = KeyValueDecoder()
10231023
decoder.userInfo[.decoder] = proxy as any DecodingProxy
10241024
_ = try decoder.decode(StubDecoder.self, from: value)
10251025
return proxy.result!
10261026
}
10271027

10281028
static func makeJSONCompatible() -> KeyValueDecoder {
1029-
let decoder = KeyValueDecoder()
1029+
var decoder = KeyValueDecoder()
10301030
decoder.nilDecodingStrategy = .nsNull
10311031
return decoder
10321032
}

Tests/KeyValueEncoderTests.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ struct KeyValueEncodedTests {
540540

541541
@Test
542542
func nilEncodingStrategy_SingleContainer() throws {
543-
let encoder = KeyValueEncoder()
543+
var encoder = KeyValueEncoder()
544544

545545
encoder.nilEncodingStrategy = .removed
546546
#expect(
@@ -568,7 +568,7 @@ struct KeyValueEncodedTests {
568568

569569
@Test
570570
func nilEncodingStrategy_UnkeyedContainer() throws {
571-
let encoder = KeyValueEncoder()
571+
var encoder = KeyValueEncoder()
572572

573573
encoder.nilEncodingStrategy = .removed
574574
#expect(
@@ -677,7 +677,7 @@ private extension KeyValueEncoder {
677677

678678
static func encodeSingleValue(nilEncodingStrategy: NilEncodingStrategy = .default,
679679
with closure: (inout any SingleValueEncodingContainer) throws -> Void) throws -> EncodedValue {
680-
let encoder = KeyValueEncoder()
680+
var encoder = KeyValueEncoder()
681681
encoder.nilEncodingStrategy = nilEncodingStrategy
682682
return try encoder.encodeValue {
683683
var container = $0.singleValueContainer()
@@ -692,11 +692,12 @@ private extension KeyValueEncoder {
692692
}
693693
}
694694

695-
static func encodeKeyedValue<K: CodingKey>(keyedBy: K.Type = K.self,
696-
nilEncodingStrategy: NilEncodingStrategy = .default,
697-
with closure: @escaping (inout KeyedEncodingContainer<K>) throws -> Void) throws
698-
-> EncodedValue {
699-
let encoder = KeyValueEncoder()
695+
static func encodeKeyedValue<K: CodingKey>(
696+
keyedBy: K.Type = K.self,
697+
nilEncodingStrategy: NilEncodingStrategy = .default,
698+
with closure: @escaping (inout KeyedEncodingContainer<K>) throws -> Void
699+
) throws -> EncodedValue {
700+
var encoder = KeyValueEncoder()
700701
encoder.nilEncodingStrategy = nilEncodingStrategy
701702
return try encoder.encodeValue {
702703
var container = $0.container(keyedBy: K.self)
@@ -711,7 +712,7 @@ private extension KeyValueEncoder {
711712
}
712713

713714
static func makeJSONCompatible() -> KeyValueEncoder {
714-
let encoder = KeyValueEncoder()
715+
var encoder = KeyValueEncoder()
715716
encoder.nilEncodingStrategy = .nsNull
716717
return encoder
717718
}

0 commit comments

Comments
 (0)