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.
This commit is contained in:
Andreas Kling 2021-01-09 19:57:06 +01:00
parent b4918bbe2f
commit 4a83a37f79
Notes: sideshowbarker 2024-07-18 23:59:27 +09:00

View file

@ -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;
};