[ox/std] Add Result::to for passing value to functions
(synced from 741026680a)
This commit is contained in:
+10
-2
@@ -197,6 +197,14 @@ struct [[nodiscard]] Result {
|
|||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr ox::Result<T> to(const auto &f) noexcept {
|
||||||
|
if (error) [[unlikely]] {
|
||||||
|
return OxError(1);
|
||||||
|
}
|
||||||
|
return f(value);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@@ -206,8 +214,8 @@ constexpr Error toError(const Error &e) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error toError(const Result<T> &ve) noexcept {
|
constexpr Error toError(const Result<T> &r) noexcept {
|
||||||
return ve.error;
|
return r.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user