12#ifndef NROS_CPP_RESULT_HPP
13#define NROS_CPP_RESULT_HPP
17#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
84 "ErrorCode numbering must match nros_ret_t (issue #229)");
103 explicit operator bool()
const {
return ok(); }
109 int32_t
raw()
const {
return static_cast<int32_t
>(code_); }
128#define NROS_TRY(expr) \
130 ::nros::Result _nros_r = (expr); \
131 if (!_nros_r.ok()) return _nros_r; \
148#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
149#define NROS_TRY_LOG(file, line, expr, ret) \
150 ::std::fprintf(stderr, "[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
152#define NROS_TRY_LOG(file, line, expr, ret) ((void)(file), (void)(line), (void)(expr), (void)(ret))
156#define NROS_TRY_RET(expr, retval) \
158 ::nros::Result _nros_r = (expr); \
159 if (!_nros_r.ok()) { \
160 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
168#define NROS_CHECK(expr) \
170 ::nros::Result _nros_r = (expr); \
171 if (!_nros_r.ok()) { \
172 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
203 e.value_ = ::std::move(
value);
214 bool ok()
const {
return ok_; }
215 explicit operator bool()
const {
return ok_; }
218 const T&
value() const& {
return value_; }
219 T&&
value() && { return ::std::move(value_); }
Definition result.hpp:198
Result error_as_result() const
Definition result.hpp:222
T & value() &
Definition result.hpp:217
const T & value() const &
Definition result.hpp:218
static Expected error(ErrorCode code)
Definition result.hpp:206
static Expected error(const Result &r)
Definition result.hpp:212
static Expected ok(T value)
Definition result.hpp:200
ErrorCode error() const
Definition result.hpp:221
T && value() &&
Definition result.hpp:219
bool ok() const
Definition result.hpp:214
static constexpr Result success()
Named constructors.
Definition result.hpp:112
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:109
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:106
constexpr Result(ErrorCode code)
Construct from a typed code.
Definition result.hpp:95
constexpr Result(int32_t raw)
Construct from a raw FFI return value (int32_t).
Definition result.hpp:97
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:100
constexpr Result()
Default-construct a success.
Definition result.hpp:93
ErrorCode
Definition result.hpp:30
@ InvalidArgument
Null pointer, empty topic name, or out-of-range value.
@ NotFound
Entity not found (topic, parameter, service…).
@ Reentrant
A blocking call was made from inside a callback.
@ PublishFailed
Publish failed.
@ BadSequence
Operation invalid in the current state (bad call sequence).
@ ServiceFailed
Service request/reply failed.
@ AlreadyExists
Already exists (duplicate declare/register).
@ Error
Generic failure not covered by a more specific code.
@ TransportError
Underlying zenoh-pico / DDS transport rejected the operation.
@ Unsupported
Operation not implemented by the active backend.
@ Full
Static pool exhausted (executor slots, subscription buffers, …).
@ Timeout
Operation deadline elapsed before completion.
@ SubscriptionFailed
Subscription create/take failed.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
@ NotAllowed
Operation not allowed for this entity/backend.