mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
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
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__
|
#ifdef __serenity__
|
||||||
ErrorOr(ErrnoCode code)
|
ErrorOr(ErrnoCode code)
|
||||||
: m_error(Error::from_errno(code))
|
: m_error(Error::from_errno(code))
|
||||||
|
@ -74,6 +80,9 @@ public:
|
||||||
ErrorOr(ErrorOr const& other) = default;
|
ErrorOr(ErrorOr const& other) = default;
|
||||||
~ErrorOr() = default;
|
~ErrorOr() = default;
|
||||||
|
|
||||||
|
ErrorOr& operator=(ErrorOr&& other) = default;
|
||||||
|
ErrorOr& operator=(ErrorOr const& other) = default;
|
||||||
|
|
||||||
T& value() { return m_value.value(); }
|
T& value() { return m_value.value(); }
|
||||||
Error& error() { return m_error.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() = default;
|
||||||
ErrorOr(ErrorOr&& other) = default;
|
ErrorOr(ErrorOr&& other) = default;
|
||||||
ErrorOr(const ErrorOr& other) = default;
|
ErrorOr(ErrorOr const& other) = default;
|
||||||
~ErrorOr() = default;
|
~ErrorOr() = default;
|
||||||
|
|
||||||
|
ErrorOr& operator=(ErrorOr&& other) = default;
|
||||||
|
ErrorOr& operator=(ErrorOr const& other) = default;
|
||||||
|
|
||||||
ErrorType& error() { return m_error.value(); }
|
ErrorType& error() { return m_error.value(); }
|
||||||
bool is_error() const { return m_error.has_value(); }
|
bool is_error() const { return m_error.has_value(); }
|
||||||
ErrorType release_error() { return m_error.release_value(); }
|
ErrorType release_error() { return m_error.release_value(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue