|
9 | 9 | #include <outcome/try.hpp> |
10 | 10 |
|
11 | 11 | namespace ystdlib::error_handling { |
| 12 | +/** |
| 13 | + * A convenience alias for Outcome's std_result. |
| 14 | + * |
| 15 | + * This alias standardizes error handling across the codebase by defaulting the error type to |
| 16 | + * `std::error_code`, which interoperates with the ystdlib::error_handling::ErrorCode framework, |
| 17 | + * making it easier to compose errors and propagate them across different modules and libraries. |
| 18 | + * |
| 19 | + * @tparam ReturnType The type returned upon success. |
| 20 | + * @tparam ErrorType The type returned upon failure. |
| 21 | + */ |
12 | 22 | template <typename ReturnType, typename ErrorType = std::error_code> |
13 | 23 | using Result = OUTCOME_V2_NAMESPACE::std_result<ReturnType, ErrorType>; |
14 | 24 |
|
15 | 25 | /** |
16 | 26 | * Default return value for ystdlib::error_handling::Result<void> when function succeeds. |
| 27 | + * |
| 28 | + * Example: |
| 29 | + * auto my_func() -> Result<void> { |
| 30 | + * // ... |
| 31 | + * return success(); |
| 32 | + * } |
17 | 33 | */ |
18 | 34 | [[nodiscard]] inline auto success() -> OUTCOME_V2_NAMESPACE::success_type<void> { |
19 | 35 | return OUTCOME_V2_NAMESPACE::success(); |
20 | 36 | } |
21 | 37 |
|
22 | 38 | /** |
23 | | - * This macro works the same way as Rust's `?` operator for error propagation. |
| 39 | + * Propagates errors like Rust's `?` operator. |
| 40 | + * |
| 41 | + * Evaluates `expr`, and if it contains an error, returns the error from the calling function. |
| 42 | + * Otherwise, extracts and returns the value. |
| 43 | + * |
| 44 | + * Only supported on AppleClang, Clang, and GCC due to reliance on Outcome's TRY macros. |
24 | 45 | */ |
25 | 46 | // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) |
26 | 47 | #define YSTDLIB_TRYX(expr) (OUTCOME_TRYX(expr)) |
27 | 48 |
|
28 | 49 | /** |
29 | | - * This macro works the same way as Rust's `?` operator for error propagation, without returning |
30 | | - * any value. |
| 50 | + * Error propagation macro for expressions that return void on success. |
| 51 | + * |
| 52 | + * Evaluates `expr`, and if it contains an error, returns the error from the calling function. |
| 53 | + * Intended for use with expressions that return `Result<void>`. |
| 54 | + * |
| 55 | + * Only supported on AppleClang, Clang, and GCC due to reliance on Outcome's TRY macros. |
31 | 56 | */ |
32 | | -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) |
| 57 | +// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while, cppcoreguidelines-macro-usage) |
33 | 58 | #define YSTDLIB_TRYV(expr) \ |
34 | 59 | do { \ |
35 | 60 | OUTCOME_TRYV(expr); \ |
|
0 commit comments