12#ifndef NROS_CPP_RESULT_HPP
13#define NROS_CPP_RESULT_HPP
17#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
81 "ErrorCode numbering must match nros_ret_t (issue #229)");
100 explicit operator bool()
const {
return ok(); }
125#define NROS_TRY(expr) \
127 ::nros::Result _nros_r = (expr); \
128 if (!_nros_r.ok()) return _nros_r; \
145#if defined(NROS_CPP_STD) || (__STDC_HOSTED__ + 0)
146#define NROS_TRY_LOG(file, line, expr, ret) \
147 ::std::fprintf(stderr, "[nros] %s:%d %s -> %d\n", (file), (line), (expr), (int)(ret))
149#define NROS_TRY_LOG(file, line, expr, ret) ((void)(file), (void)(line), (void)(expr), (void)(ret))
153#define NROS_TRY_RET(expr, retval) \
155 ::nros::Result _nros_r = (expr); \
156 if (!_nros_r.ok()) { \
157 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
165#define NROS_CHECK(expr) \
167 ::nros::Result _nros_r = (expr); \
168 if (!_nros_r.ok()) { \
169 NROS_TRY_LOG(__FILE__, __LINE__, #expr, _nros_r.raw()); \
200 e.value_ = ::std::move(
value);
211 bool ok()
const {
return ok_; }
212 explicit operator bool()
const {
return ok_; }
216 T&&
value() && { return ::std::move(value_); }
Definition result.hpp:195
Result error_as_result() const
Definition result.hpp:219
T & value() &
Definition result.hpp:214
const T & value() const &
Definition result.hpp:215
static Expected error(ErrorCode code)
Definition result.hpp:203
static Expected error(const Result &r)
Definition result.hpp:209
static Expected ok(T value)
Definition result.hpp:197
ErrorCode error() const
Definition result.hpp:218
T && value() &&
Definition result.hpp:216
bool ok() const
Definition result.hpp:211
static constexpr Result success()
Named constructors.
Definition result.hpp:109
int32_t raw() const
Get the raw integer code (for FFI interop).
Definition result.hpp:106
ErrorCode code() const
Get the underlying error code.
Definition result.hpp:103
constexpr Result(ErrorCode code)
Construct from a typed code.
Definition result.hpp:92
constexpr Result(int32_t raw)
Construct from a raw FFI return value (int32_t).
Definition result.hpp:94
bool ok() const
Returns true if the operation succeeded.
Definition result.hpp:97
constexpr Result()
Default-construct a success.
Definition result.hpp:90
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.
@ Rejected
Rejected (QoS/ABI incompatibility).
@ SubscriptionFailed
Subscription create/take failed.
@ TryAgain
Transient — no data ready yet (non-blocking take). Retry later.
@ NotAllowed
Operation not allowed for this entity/backend.