diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-09 19:57:06 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-09 19:57:50 +0100 |
commit | 4a83a37f798788332a06e0cef1bf6a81d5983be4 (patch) | |
tree | e7d315fa18420107123b7f339a57aabf2fee9527 | |
parent | b4918bbe2f7bc8139191ca444be481f18040247e (diff) | |
download | serenity-4a83a37f798788332a06e0cef1bf6a81d5983be4.zip |
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.
-rw-r--r-- | AK/Result.h | 21 |
1 files 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<ValueType> m_result; Optional<ErrorType> m_error; @@ -113,6 +117,11 @@ public: return m_error.has_value(); } + void release_error() + { + return m_error.release_value(); + } + private: Optional<ErrorType> m_error; }; |