Skip to content

Commit

Permalink
Merge pull request #51 from RakuyoKit/feature/EmptyError
Browse files Browse the repository at this point in the history
feat: Add `EmptyError`
  • Loading branch information
rakuyoMo authored Jun 28, 2024
2 parents 1e16620 + cda43e0 commit 4c39352
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/Core/Utilities/EmptyError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// EmptyError.swift
// RakuyoKit
//
// Created by Rakuyo on 2024/5/27.
// Copyright © 2024 RakuyoKit. All rights reserved.
//

import Foundation

public typealias NoErrorResult<Success> = Result<Success, EmptyError>

// MARK: - EmptyError

/// Placeholder when `.failure` is needed but `Error` is not needed
///
/// `Result<Success, Never>` means no error will occur, so `.failure` cannot be constructed in this case
/// But sometimes `.failure` is needed but it doesn't matter what kind of error is thrown.
/// It would be troublesome to construct a specific Error in this case. In this case, `EmptyError` can be used
public struct EmptyError: Error, ExpressibleByNilLiteral {
public init() { }
public init(nilLiteral _: ()) { }
}

0 comments on commit 4c39352

Please sign in to comment.