Slather logo

Coverage for "RoutingResult.swift" : 100.00%

(20 of 20 relevant lines covered)

RouteComposer/Classes/RoutingResult.swift

1
//
2
// RouteComposer
3
// RoutingResult.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import Foundation
14
15
/// The result of the navigation process
16
///
17
/// - success: The request to process the navigation resulted in a successful navigation to the destination.
18
/// - failure: The request to process the navigation was not successful.
19
public enum RoutingResult {
20
21
    /// The request to process the navigation resulted in a successful navigation to the destination.
22
    case success
23
24
    /// The request to process the navigation was not successful.
25
    case failure(Error)
26
27
}
28
29
// MARK: Helper methods
30
31
public extension RoutingResult {
32
33
    /// Returns `true` if `RoutingResult` is `success`
34
    var isSuccessful: Bool {
601x
35
        guard case .success = self else {
601x
36
            return false
34x
37
        }
567x
38
        return true
567x
39
    }
601x
40
41
    /// Returns SDK's `Result` value.
42
    var swiftResult: Result<Void, Error> {
2x
43
        switch self {
2x
44
        case .success:
2x
45
            return .success(())
1x
46
        case let .failure(error):
2x
47
            return .failure(error)
1x
48
        }
2x
49
    }
2x
50
51
    /// Returns the `Error` instance of the `RoutingResult`.
52
    /// - Throws: The `RoutingError` if `RoutingResult` is `success`.
53
    func getError() throws -> Error {
100x
54
        guard case let .failure(error) = self else {
100x
55
            throw RoutingError.generic(.init("Navigation is successful"))
97x
56
        }
97x
57
        return error
3x
58
    }
100x
59
60
}