summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-09 19:57:06 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-09 19:57:50 +0100
commit4a83a37f798788332a06e0cef1bf6a81d5983be4 (patch)
treee7d315fa18420107123b7f339a57aabf2fee9527
parentb4918bbe2f7bc8139191ca444be481f18040247e (diff)
downloadserenity-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.h21
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;
};