From 1d51935d4349f153819e274631bd98fd82be1b3e Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 30 Nov 2022 17:10:43 +0100 Subject: [PATCH] Make Result able to return an error string --- luna/Result.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/luna/Result.h b/luna/Result.h index 1aec130f..13dfd58a 100644 --- a/luna/Result.h +++ b/luna/Result.h @@ -2,6 +2,7 @@ #include #include #include +#include #include struct Error @@ -92,6 +93,12 @@ template class Result return {m_error}; } + const char* error_string() + { + check(has_error()); + return ::error_string(m_error); + } + T value() { check(has_value()); @@ -224,6 +231,12 @@ template <> class Result return {m_error}; } + const char* error_string() + { + check(has_error()); + return ::error_string(m_error); + } + void value() { check(has_value()); @@ -242,7 +255,7 @@ template <> class Result }; // clang-format off -#define err Error{0} +#define err(x) Error{x} // clang-format on #define TRY(expr) \