Skip to content

Commit e7efa6c

Browse files
committed
stdlib: Make Result methods inlinable
The "Result" type is expected to have no overhead when used. This requires the member functions to be inlinable. Which is probably okay for library evolution, because it's unlikely that those methods change in an incompatible way.
1 parent d52ddf4 commit e7efa6c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

stdlib/public/core/Result.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public enum Result<Success, Failure: Error> {
3838
/// instance.
3939
/// - Returns: A `Result` instance with the result of evaluating `transform`
4040
/// as the new success value if this instance represents a success.
41+
@inlinable
4142
public func map<NewSuccess>(
4243
_ transform: (Success) -> NewSuccess
4344
) -> Result<NewSuccess, Failure> {
@@ -75,6 +76,7 @@ public enum Result<Success, Failure: Error> {
7576
/// instance.
7677
/// - Returns: A `Result` instance with the result of evaluating `transform`
7778
/// as the new failure value if this instance represents a failure.
79+
@inlinable
7880
public func mapError<NewFailure>(
7981
_ transform: (Failure) -> NewFailure
8082
) -> Result<Success, NewFailure> {
@@ -112,6 +114,7 @@ public enum Result<Success, Failure: Error> {
112114
/// instance.
113115
/// - Returns: A `Result` instance with the result of evaluating `transform`
114116
/// as the new failure value if this instance represents a failure.
117+
@inlinable
115118
public func flatMap<NewSuccess>(
116119
_ transform: (Success) -> Result<NewSuccess, Failure>
117120
) -> Result<NewSuccess, Failure> {
@@ -130,6 +133,7 @@ public enum Result<Success, Failure: Error> {
130133
/// instance.
131134
/// - Returns: A `Result` instance, either from the closure or the previous
132135
/// `.success`.
136+
@inlinable
133137
public func flatMapError<NewFailure>(
134138
_ transform: (Failure) -> Result<Success, NewFailure>
135139
) -> Result<Success, NewFailure> {
@@ -157,6 +161,7 @@ public enum Result<Success, Failure: Error> {
157161
///
158162
/// - Returns: The success value, if the instance represents a success.
159163
/// - Throws: The failure value, if the instance represents a failure.
164+
@inlinable
160165
public func get() throws -> Success {
161166
switch self {
162167
case let .success(success):

0 commit comments

Comments
 (0)