Skip to content

Commit

Permalink
feat: Add EmptyError
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Jun 28, 2024
1 parent 1e16620 commit cda43e0
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 cda43e0

Please sign in to comment.