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

Commit aee2b53

Browse files
committed
Annotate TaskResult for binary resilience
1 parent febc96f commit aee2b53

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extension TaskResult {
1111
/// value as the parameter, to derive a new value.
1212
///
1313
/// Use the `map` method with a closure that produces a new value.
14+
@_inlineable
1415
public func map<NewValue>(_ transform: (Value) throws -> NewValue) -> TaskResult<NewValue> {
1516
switch self {
1617
case .success(let value):
@@ -28,6 +29,7 @@ extension TaskResult {
2829
/// value as the parameter, to derive a new result.
2930
///
3031
/// Use `flatMap` with a closure that itself returns a result.
32+
@_inlineable
3133
public func flatMap<NewValue>(_ transform: (Value) throws -> TaskResult<NewValue>) -> TaskResult<NewValue> {
3234
switch self {
3335
case .success(let value):
@@ -45,6 +47,7 @@ extension TaskResult {
4547
extension TaskResult {
4648
/// Performs a coalescing operation, returning the result of unwrapping the
4749
/// success value of `result`, or `defaultValue` in case of an error.
50+
@_inlineable
4851
public static func ?? (result: TaskResult<Value>, defaultValue: @autoclosure() throws -> Value) rethrows -> Value {
4952
switch result {
5053
case .success(let value):
@@ -56,6 +59,7 @@ extension TaskResult {
5659

5760
/// Performs a coalescing operation, the wrapped success value `result`, or
5861
/// that of `defaultValue` in case of an error.
62+
@_inlineable
5963
public static func ?? (result: TaskResult<Value>, defaultValue: @autoclosure() throws -> TaskResult<Value>) rethrows -> TaskResult<Value> {
6064
return try result.withValues(ifLeft: { _ in try defaultValue() }, ifRight: TaskResult.success)
6165
}

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 -> Right) {
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)