Loading...
Searching...
No Matches
result.hpp
1
2/* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE.txt)
6 */
7
8#ifndef BOOST_REDIS_ADAPTER_RESULT_HPP
9#define BOOST_REDIS_ADAPTER_RESULT_HPP
10
11#include <boost/redis/error.hpp>
12#include <boost/redis/resp3/type.hpp>
13
14#include <boost/system/result.hpp>
15
16#include <string>
17
18namespace boost::redis::adapter {
19
30
37inline bool operator==(error const& a, error const& b)
38{
39 return a.data_type == b.data_type && a.diagnostic == b.diagnostic;
40}
41
48inline bool operator!=(error const& a, error const& b) { return !(a == b); }
49
53template <class Value>
54using result = system::result<Value, error>;
55
56BOOST_NORETURN inline void throw_exception_from_error(error const& e, boost::source_location const&)
57{
58 system::error_code ec;
59 switch (e.data_type) {
63 default: BOOST_ASSERT_MSG(false, "Unexpected data type.");
64 }
65
66 throw system::system_error(ec, e.diagnostic);
67}
68
69} // namespace boost::redis::adapter
70
71#endif // BOOST_REDIS_ADAPTER_RESULT_HPP
type
RESP3 data types.
Definition type.hpp:24
system::result< Value, error > result
Stores response to individual Redis commands.
Definition result.hpp:54
@ resp3_blob_error
Got RESP3 blob_error.
@ resp3_null
Got RESP3 null.
@ resp3_simple_error
Got RESP3 simple error.
Stores any resp3 error.
Definition result.hpp:23
resp3::type data_type
RESP3 error data type.
Definition result.hpp:25
bool operator!=(error const &a, error const &b)
Compares two error objects for difference.
Definition result.hpp:48
bool operator==(error const &a, error const &b)
Compares two error objects for equality.
Definition result.hpp:37
std::string diagnostic
Diagnostic error message sent by Redis.
Definition result.hpp:28