Skip to content

Commit 8f07152

Browse files
committed
Improve comments for result macros
1 parent db9fe23 commit 8f07152

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/ystdlib/error_handling/Result.hpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,52 @@
99
#include <outcome/try.hpp>
1010

1111
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+
*/
1222
template <typename ReturnType, typename ErrorType = std::error_code>
1323
using Result = OUTCOME_V2_NAMESPACE::std_result<ReturnType, ErrorType>;
1424

1525
/**
1626
* 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+
* }
1733
*/
1834
[[nodiscard]] inline auto success() -> OUTCOME_V2_NAMESPACE::success_type<void> {
1935
return OUTCOME_V2_NAMESPACE::success();
2036
}
2137

2238
/**
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.
2445
*/
2546
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
2647
#define YSTDLIB_TRYX(expr) (OUTCOME_TRYX(expr))
2748

2849
/**
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.
3156
*/
32-
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
57+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-do-while, cppcoreguidelines-macro-usage)
3358
#define YSTDLIB_TRYV(expr) \
3459
do { \
3560
OUTCOME_TRYV(expr); \

0 commit comments

Comments
 (0)