12#ifndef NROS_CPP_RESULT_HPP
13#define NROS_CPP_RESULT_HPP
17#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
65 explicit operator bool()
const {
return ok(); }
90#define NROS_TRY(expr) \
92 ::nros::Result _nros_r = (expr); \
93 if (!_nros_r.ok()) return _nros_r; \
110#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
111#define NROS_TRY_LOG(file, line, expr, ret) \
112 ::std::fprintf(stderr, "[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
114#define NROS_TRY_LOG(file, line, expr, ret) ((void)(file), (void)(line), (void)(expr), (void)(ret))
118#define NROS_TRY_RET(expr, retval) \
120 ::nros::Result _nros_r = (expr); \
121 if (!_nros_r.ok()) { \
122 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
130#define NROS_CHECK(expr) \
132 ::nros::Result _nros_r = (expr); \
133 if (!_nros_r.ok()) { \
134 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
165 e.value_ = ::std::move(
value);
176 bool ok()
const {
return ok_; }
177 explicit operator bool()
const {
return ok_; }
181 T&&
value() && { return ::std::move(value_); }
Definition result.hpp:160
Result error_as_result() const
Definition result.hpp:184
T & value() &
Definition result.hpp:179
const T & value() const &
Definition result.hpp:180
static Expected error(ErrorCode code)
Definition result.hpp:168
static Expected error(const Result &r)
Definition result.hpp:174
static Expected ok(T value)
Definition result.hpp:162
ErrorCode error() const
Definition result.hpp:183
T && value() &&
Definition result.hpp:181
bool ok() const
Definition result.hpp:176
static constexpr Result success()
Named constructors.
Definition result.hpp:74
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:71
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:68
constexpr Result(ErrorCode code)
Construct from a typed code.
Definition result.hpp:57
constexpr Result(int32_t raw)
Construct from a raw FFI return value (int32_t).
Definition result.hpp:59
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:62
constexpr Result()
Default-construct a success.
Definition result.hpp:55
ErrorCode
Definition result.hpp:26
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
@ Reentrant
A blocking call was made from inside a callback.
@ Error
Generic failure not covered by a more specific code.
@ TransportError
Underlying zenoh-pico / DDS transport rejected the operation.
@ Full
Static pool exhausted (executor slots, subscription buffers, …).
@ Timeout
Operation deadline elapsed before completion.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.