Skip to content
This repository was archived by the owner on Aug 29, 2022. It is now read-only.

Commit e358275

Browse files
committed
Annotate TaskResult for binary resilience
1 parent 1e70003 commit e358275

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Sources/Task/Either.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public protocol Either {
4141

4242
extension Either where Left == Error {
4343
/// Derive a success value by calling a failable function `body`.
44+
@_inlineable
4445
public init(from body: () throws -> Right) {
4546
do {
4647
try self.init(right: body())
@@ -50,6 +51,7 @@ extension Either where Left == Error {
5051
}
5152

5253
/// Returns the success value or throws the error.
54+
@_inlineable
5355
public func extract() throws -> Right {
5456
return try withValues(ifLeft: { throw $0 }, ifRight: { $0 })
5557
}

Sources/Task/ResultRecovery.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extension TaskResult {
1010
/// Performs a coalescing operation, returning the result of unwrapping the
1111
/// success value of `result`, or `defaultValue` in case of an error.
12+
@_inlineable
1213
public static func ?? (result: TaskResult<Value>, defaultValue: @autoclosure() throws -> Value) rethrows -> Value {
1314
switch result {
1415
case .success(let value):
@@ -20,6 +21,7 @@ extension TaskResult {
2021

2122
/// Performs a coalescing operation, the wrapped success value `result`, or
2223
/// that of `defaultValue` in case of an error.
24+
@_inlineable
2325
public static func ?? (result: TaskResult<Value>, defaultValue: @autoclosure() throws -> TaskResult<Value>) rethrows -> TaskResult<Value> {
2426
return try result.withValues(ifLeft: { _ in try defaultValue() }, ifRight: TaskResult.success)
2527
}

Sources/Task/TaskResult.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public enum TaskResult<Value> {
1919

2020
extension TaskResult {
2121
/// Creates an instance storing a successful `value`.
22+
@_inlineable
2223
public init(success value: @autoclosure() throws -> Value) {
2324
self.init(from: value)
2425
}
2526

2627
/// Creates an instance storing an `error` describing the failure.
28+
@_inlineable
2729
public init(failure error: Error) {
2830
self = .failure(error)
2931
}
@@ -50,6 +52,7 @@ private enum TaskResultInitializerError: Error {
5052
extension TaskResult where Value == Void {
5153
/// Creates the success value.
5254
@available(swift 4)
55+
@_inlineable
5356
public init() {
5457
self = .success(())
5558
}
@@ -58,14 +61,17 @@ extension TaskResult where Value == Void {
5861
// MARK: - Compatibility with Protocol Extensions
5962

6063
extension TaskResult: Either {
64+
@_inlineable
6165
public init(left error: Error) {
6266
self = .failure(error)
6367
}
6468

69+
@_inlineable
6570
public init(right value: Value) {
6671
self = .success(value)
6772
}
6873

74+
@_inlineable
6975
public func withValues<Return>(ifLeft left: (Error) throws -> Return, ifRight right: (Value) throws -> Return) rethrows -> Return {
7076
switch self {
7177
case let .success(value):

0 commit comments

Comments
 (0)