From 4a83a37f798788332a06e0cef1bf6a81d5983be4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 9 Jan 2021 19:57:06 +0100 Subject: AK: Add release_value() and release_error() to AK::Result These are nice when you want to move something out of the result, and match the API we already have for Optional. --- AK/Result.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/AK/Result.h b/AK/Result.h index bc1cf3300c..e95d60ef65 100644 --- a/AK/Result.h +++ b/AK/Result.h @@ -54,12 +54,6 @@ public: { } - Result(const ValueType& res, const ErrorType& error) - : m_result(res) - , m_error(error) - { - } - Result(Result&& other) = default; Result(const Result& other) = default; ~Result() = default; @@ -79,6 +73,16 @@ public: return m_error.has_value(); } + ValueType release_value() + { + return m_result.release_value(); + } + + ErrorType release_error() + { + return m_error.release_value(); + } + private: Optional m_result; Optional m_error; @@ -113,6 +117,11 @@ public: return m_error.has_value(); } + void release_error() + { + return m_error.release_value(); + } + private: Optional m_error; }; -- cgit v1.2.3