57 return "InvalidAddress";
59 return "DivisionByZero";
61 return "InvalidInstruction";
63 return "SegmentationFault";
67 return "ProcessNotFound";
69 return "PermissionDenied";
73 return "DeadlockDetected";
75 return "InvalidState";
77 return "InvalidArgument";
79 return "ResourceBusy";
83 return "AlreadyExists";
91 return "NotImplemented";
103 template <
typename T>
class [[nodiscard]]
Result
115 assert(code !=
ErrorCode::Ok &&
"Cannot create error Result with Ok code");
120 [[nodiscard]]
bool isOk() const noexcept
122 return std::holds_alternative<T>(
storage_);
128 return std::holds_alternative<ErrorCode>(
storage_);
133 [[nodiscard]]
const T &
value() const &
135 assert(
isOk() &&
"Accessing value of error Result");
143 assert(
isOk() &&
"Accessing value of error Result");
144 return std::get<T>(std::move(
storage_));
151 assert(
isOk() &&
"Accessing value of error Result");
159 assert(
isError() &&
"Accessing errorCode of ok Result");
160 return std::get<ErrorCode>(
storage_);
164 [[nodiscard]] T
valueOr(T defaultValue)
const &
185 template <>
class [[nodiscard]]
Result<void>
197 assert(code !=
ErrorCode::Ok &&
"Cannot create error Result with Ok code");
202 [[nodiscard]]
bool isOk() const noexcept
bool isError() const noexcept
Returns true if this Result represents failure.
ErrorCode errorCode() const noexcept
Returns the error code (Ok if successful).
bool isOk() const noexcept
Returns true if this Result represents success.
static Result ok()
Constructs a successful void Result.
static Result error(ErrorCode code)
Constructs a failed void Result with the given error code.
ErrorCode errorCode() const noexcept
Returns the error code.
const T & value() const &
Returns a const reference to the success value.
bool isOk() const noexcept
Returns true if this Result holds a success value.
std::variant< T, ErrorCode > storage_
bool isError() const noexcept
Returns true if this Result holds an error code.
static Result error(ErrorCode code)
Constructs a failed Result with the given error code.
static Result ok(T value)
Constructs a successful Result containing the given value.
T & value() &
Returns a mutable reference to the success value.
T valueOr(T defaultValue) const &
Returns the value if ok, or the provided default value if error.
T && value() &&
Returns an rvalue reference to the success value (move semantics).
@ Ok
No interrupt — normal execution.
ErrorCode
Error codes returned by kernel subsystem operations.
constexpr std::string_view errorCodeToString(ErrorCode code) noexcept
Returns a human-readable name for the given error code.