mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
b4918bbe2f
commit
4a83a37f79
Notes:
sideshowbarker
2024-07-18 23:59:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4a83a37f798
1 changed files with 15 additions and 6 deletions
21
AK/Result.h
21
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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue