mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09: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: 4a83a37f79
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(Result&& other) = default;
|
||||||
Result(const Result& other) = default;
|
Result(const Result& other) = default;
|
||||||
~Result() = default;
|
~Result() = default;
|
||||||
|
@ -79,6 +73,16 @@ public:
|
||||||
return m_error.has_value();
|
return m_error.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueType release_value()
|
||||||
|
{
|
||||||
|
return m_result.release_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorType release_error()
|
||||||
|
{
|
||||||
|
return m_error.release_value();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<ValueType> m_result;
|
Optional<ValueType> m_result;
|
||||||
Optional<ErrorType> m_error;
|
Optional<ErrorType> m_error;
|
||||||
|
@ -113,6 +117,11 @@ public:
|
||||||
return m_error.has_value();
|
return m_error.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void release_error()
|
||||||
|
{
|
||||||
|
return m_error.release_value();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<ErrorType> m_error;
|
Optional<ErrorType> m_error;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue