[ox/std] Add Error::reoriginate
All checks were successful
Build / build (push) Successful in 1m13s

This commit is contained in:
2026-01-28 00:46:55 -06:00
parent 8c4add57e4
commit 11e75cb6ca

View File

@@ -37,7 +37,7 @@ using ErrorCode = uint16_t;
struct [[nodiscard]] Error {
std::source_location src;
ox::CString msg = nullptr;
CString msg = nullptr;
ErrorCode errCode = 0;
constexpr Error() noexcept = default;
@@ -51,7 +51,7 @@ struct [[nodiscard]] Error {
explicit constexpr Error(
ErrorCode const errCode,
ox::CString msg,
CString const msg,
std::source_location const &src = std::source_location::current()) noexcept:
src{src},
msg{msg},
@@ -62,6 +62,18 @@ struct [[nodiscard]] Error {
return errCode;
}
constexpr Error reoriginate(
ErrorCode const pErrCode,
CString const pMsg = nullptr,
std::source_location const &pSrc = std::source_location::current()) const noexcept {
return Error{pErrCode, pMsg, pSrc};
}
constexpr Error reoriginate(
std::source_location const &pSrc = std::source_location::current()) const noexcept {
return Error{errCode, msg, pSrc};
}
};
[[nodiscard]]
@@ -112,13 +124,13 @@ struct Exception: public std::exception {
[[noreturn]]
void panic(
Error const &err,
char const *panicMsg,
CString panicMsg,
std::source_location const &src = std::source_location::current()) noexcept;
template<typename T>
struct [[nodiscard]] Result {
using type = typename remove_reference<T>::type;
using type = remove_reference_t<T>;
T value;
Error error;