AK: Add some more ways to construct Error and ErrorOr<T>
This is preparation for using Error in the kernel instead of KResult.
This commit is contained in:
parent
5e473a63d3
commit
7ee10c6926
Notes:
sideshowbarker
2024-07-18 01:23:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7ee10c69264
1 changed files with 20 additions and 1 deletions
21
AK/Error.h
21
AK/Error.h
|
@ -58,6 +58,12 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(U&& value) requires(!IsSame<RemoveCVReference<U>, ErrorOr<T>>)
|
||||
: m_value(forward<U>(value))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef __serenity__
|
||||
ErrorOr(ErrnoCode code)
|
||||
: m_error(Error::from_errno(code))
|
||||
|
@ -74,6 +80,9 @@ public:
|
|||
ErrorOr(ErrorOr const& other) = default;
|
||||
~ErrorOr() = default;
|
||||
|
||||
ErrorOr& operator=(ErrorOr&& other) = default;
|
||||
ErrorOr& operator=(ErrorOr const& other) = default;
|
||||
|
||||
T& value() { return m_value.value(); }
|
||||
Error& error() { return m_error.value(); }
|
||||
|
||||
|
@ -98,11 +107,21 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef __serenity__
|
||||
ErrorOr(ErrnoCode code)
|
||||
: m_error(Error::from_errno(code))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrorOr() = default;
|
||||
ErrorOr(ErrorOr&& other) = default;
|
||||
ErrorOr(const ErrorOr& other) = default;
|
||||
ErrorOr(ErrorOr const& other) = default;
|
||||
~ErrorOr() = default;
|
||||
|
||||
ErrorOr& operator=(ErrorOr&& other) = default;
|
||||
ErrorOr& operator=(ErrorOr const& other) = default;
|
||||
|
||||
ErrorType& error() { return m_error.value(); }
|
||||
bool is_error() const { return m_error.has_value(); }
|
||||
ErrorType release_error() { return m_error.release_value(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue