Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sendable conformance #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/AnyCodable/AnyCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ import Foundation
- SeeAlso: `AnyEncodable`
- SeeAlso: `AnyDecodable`
*/
#if compiler(>=5.6)
@preconcurrency @frozen public struct AnyCodable: Codable, @unchecked Sendable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#else
@frozen public struct AnyCodable: Codable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#endif

extension AnyCodable: _AnyEncodable, _AnyDecodable {}

Expand Down
10 changes: 10 additions & 0 deletions Sources/AnyCodable/AnyDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ import Foundation
let decoder = JSONDecoder()
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
*/
#if compiler(>=5.6)
@preconcurrency @frozen public struct AnyDecodable: Decodable, @unchecked Sendable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#else
@frozen public struct AnyDecodable: Decodable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#endif

@usableFromInline
protocol _AnyDecodable {
Expand Down
10 changes: 10 additions & 0 deletions Sources/AnyCodable/AnyEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ import Foundation
let encoder = JSONEncoder()
let json = try! encoder.encode(dictionary)
*/
#if compiler(>=5.6)
@preconcurrency @frozen public struct AnyEncodable: Encodable, @unchecked Sendable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#else
@frozen public struct AnyEncodable: Encodable {
public let value: Any

public init<T>(_ value: T?) {
self.value = value ?? ()
}
}
#endif

@usableFromInline
protocol _AnyEncodable {
Expand Down