Skip to content

Commit 866d2ad

Browse files
committed
Avoid CXX inherent method warning
Replace direct CXX bridge bindings for C++ member functions with lbug_rs free-function wrappers and update the Rust call sites to use those wrappers, eliminating the #[automatically_derived] warnings emitted for generated inherent impl blocks while preserving the existing FFI behavior.
1 parent 3a661e8 commit 866d2ad

7 files changed

Lines changed: 178 additions & 90 deletions

File tree

include/lbug_rs.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ struct TypeListBuilder {
3232
};
3333

3434
std::unique_ptr<TypeListBuilder> create_type_list();
35+
inline void type_list_insert(TypeListBuilder& list, std::unique_ptr<lbug::common::LogicalType> type) {
36+
list.insert(std::move(type));
37+
}
3538

3639
struct QueryParams {
3740
std::unordered_map<std::string, std::unique_ptr<lbug::common::Value>> inputParams;
@@ -42,6 +45,10 @@ struct QueryParams {
4245
};
4346

4447
std::unique_ptr<QueryParams> new_params();
48+
inline void query_params_insert(QueryParams& params, const rust::Str key,
49+
std::unique_ptr<lbug::common::Value> value) {
50+
params.insert(key, std::move(value));
51+
}
4552

4653
std::unique_ptr<lbug::common::LogicalType> create_logical_type(lbug::common::LogicalTypeID id);
4754
std::unique_ptr<lbug::common::LogicalType> create_logical_type_list(
@@ -93,6 +100,10 @@ inline uint32_t logical_type_get_decimal_precision(const lbug::common::LogicalTy
93100
inline uint32_t logical_type_get_decimal_scale(const lbug::common::LogicalType& logicalType) {
94101
return lbug::common::DecimalType::getScale(logicalType);
95102
}
103+
inline lbug::common::LogicalTypeID logical_type_get_logical_type_id(
104+
const lbug::common::LogicalType& logicalType) {
105+
return logicalType.getLogicalTypeID();
106+
}
96107

97108
/* Database */
98109
std::unique_ptr<lbug::main::Database> new_database(std::string_view databasePath,
@@ -110,20 +121,56 @@ inline std::unique_ptr<lbug::main::QueryResult> connection_query(lbug::main::Con
110121
std::string_view query) {
111122
return connection.query(query);
112123
}
124+
inline std::unique_ptr<lbug::main::PreparedStatement> connection_prepare(
125+
lbug::main::Connection& connection, std::string_view query) {
126+
return connection.prepare(query);
127+
}
128+
inline uint64_t connection_get_max_num_thread_for_exec(lbug::main::Connection& connection) {
129+
return connection.getMaxNumThreadForExec();
130+
}
131+
inline void connection_set_max_num_thread_for_exec(lbug::main::Connection& connection,
132+
uint64_t numThreads) {
133+
connection.setMaxNumThreadForExec(numThreads);
134+
}
135+
inline void connection_interrupt(lbug::main::Connection& connection) {
136+
connection.interrupt();
137+
}
138+
inline void connection_set_query_timeout(lbug::main::Connection& connection, uint64_t timeoutMs) {
139+
connection.setQueryTimeOut(timeoutMs);
140+
}
113141

114142
/* PreparedStatement */
115143
rust::String prepared_statement_error_message(const lbug::main::PreparedStatement& statement);
116144
inline lbug::common::StatementType prepared_statement_get_statement_type(
117145
const lbug::main::PreparedStatement& statement) {
118146
return statement.getStatementType();
119147
}
148+
inline bool prepared_statement_is_success(const lbug::main::PreparedStatement& statement) {
149+
return statement.isSuccess();
150+
}
120151

121152
/* QueryResult */
122153
rust::String query_result_to_string(const lbug::main::QueryResult& result);
123154
rust::String query_result_get_error_message(const lbug::main::QueryResult& result);
155+
inline bool query_result_is_success(const lbug::main::QueryResult& result) {
156+
return result.isSuccess();
157+
}
158+
inline bool query_result_has_next(const lbug::main::QueryResult& result) {
159+
return result.hasNext();
160+
}
161+
inline std::shared_ptr<lbug::processor::FlatTuple> query_result_get_next(
162+
lbug::main::QueryResult& result) {
163+
return result.getNext();
164+
}
124165

125166
double query_result_get_compiling_time(const lbug::main::QueryResult& result);
126167
double query_result_get_execution_time(const lbug::main::QueryResult& result);
168+
inline size_t query_result_get_num_columns(const lbug::main::QueryResult& result) {
169+
return result.getNumColumns();
170+
}
171+
inline uint64_t query_result_get_num_tuples(const lbug::main::QueryResult& result) {
172+
return result.getNumTuples();
173+
}
127174

128175
std::unique_ptr<std::vector<lbug::common::LogicalType>> query_result_column_data_types(
129176
const lbug::main::QueryResult& query_result);
@@ -156,6 +203,7 @@ const lbug::common::Value& recursive_rel_get_nodes(const lbug::common::Value& va
156203
const lbug::common::Value& recursive_rel_get_rels(const lbug::common::Value& val);
157204

158205
/* FlatTuple */
206+
uint32_t flat_tuple_len(const lbug::processor::FlatTuple& flatTuple);
159207
const lbug::common::Value& flat_tuple_get_value(const lbug::processor::FlatTuple& flatTuple,
160208
uint32_t index);
161209

@@ -185,6 +233,42 @@ inline lbug::common::PhysicalTypeID value_get_physical_type(const lbug::common::
185233
return value.getDataType().getPhysicalType();
186234
}
187235
rust::String value_to_string(const lbug::common::Value& val);
236+
inline bool value_get_bool(const lbug::common::Value& value) {
237+
return value.getValue<bool>();
238+
}
239+
inline int8_t value_get_i8(const lbug::common::Value& value) {
240+
return value.getValue<int8_t>();
241+
}
242+
inline int16_t value_get_i16(const lbug::common::Value& value) {
243+
return value.getValue<int16_t>();
244+
}
245+
inline int32_t value_get_i32(const lbug::common::Value& value) {
246+
return value.getValue<int32_t>();
247+
}
248+
inline int64_t value_get_i64(const lbug::common::Value& value) {
249+
return value.getValue<int64_t>();
250+
}
251+
inline uint8_t value_get_u8(const lbug::common::Value& value) {
252+
return value.getValue<uint8_t>();
253+
}
254+
inline uint16_t value_get_u16(const lbug::common::Value& value) {
255+
return value.getValue<uint16_t>();
256+
}
257+
inline uint32_t value_get_u32(const lbug::common::Value& value) {
258+
return value.getValue<uint32_t>();
259+
}
260+
inline uint64_t value_get_u64(const lbug::common::Value& value) {
261+
return value.getValue<uint64_t>();
262+
}
263+
inline float value_get_float(const lbug::common::Value& value) {
264+
return value.getValue<float>();
265+
}
266+
inline double value_get_double(const lbug::common::Value& value) {
267+
return value.getValue<double>();
268+
}
269+
inline bool value_is_null(const lbug::common::Value& value) {
270+
return value.isNull();
271+
}
188272

189273
std::unique_ptr<lbug::common::Value> create_value_string(lbug::common::LogicalTypeID typ,
190274
const rust::Slice<const unsigned char> value);
@@ -237,6 +321,9 @@ struct ValueListBuilder {
237321
std::unique_ptr<lbug::common::Value> get_list_value(std::unique_ptr<lbug::common::LogicalType> typ,
238322
std::unique_ptr<ValueListBuilder> value);
239323
std::unique_ptr<ValueListBuilder> create_list();
324+
inline void value_list_insert(ValueListBuilder& list, std::unique_ptr<lbug::common::Value> value) {
325+
list.insert(std::move(value));
326+
}
240327

241328
inline std::string_view string_view_from_str(rust::Str s) {
242329
return {s.data(), s.size()};

src/connection.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,12 @@ impl<'a> Connection<'a> {
9898
/// # Arguments
9999
/// * `num_threads`: The maximum number of threads to use for execution in the current connection
100100
pub fn set_max_num_threads_for_exec(&mut self, num_threads: u64) {
101-
self.conn
102-
.get_mut()
103-
.pin_mut()
104-
.setMaxNumThreadForExec(num_threads);
101+
ffi::connection_set_max_num_thread_for_exec(self.conn.get_mut().pin_mut(), num_threads);
105102
}
106103

107104
/// Returns the maximum number of threads used for execution in the current connection
108105
pub fn get_max_num_threads_for_exec(&self) -> u64 {
109-
unsafe { (*self.conn.get()).pin_mut().getMaxNumThreadForExec() }
106+
ffi::connection_get_max_num_thread_for_exec(unsafe { (*self.conn.get()).pin_mut() })
110107
}
111108

112109
/// Prepares the given query and returns the prepared statement. [`PreparedStatement`]s can be run
@@ -116,9 +113,11 @@ impl<'a> Connection<'a> {
116113
/// * `query`: The query to prepare. See <https://ladybugdb.com/docs/cypher> for details on the
117114
/// query format.
118115
pub fn prepare(&self, query: &str) -> Result<PreparedStatement, Error> {
119-
let statement =
120-
unsafe { (*self.conn.get()).pin_mut() }.prepare(ffi::StringView::new(query))?;
121-
if statement.isSuccess() {
116+
let statement = ffi::connection_prepare(
117+
unsafe { (*self.conn.get()).pin_mut() },
118+
ffi::StringView::new(query),
119+
)?;
120+
if ffi::prepared_statement_is_success(&statement) {
122121
Ok(PreparedStatement { statement })
123122
} else {
124123
Err(Error::FailedPreparedStatement(
@@ -143,7 +142,7 @@ impl<'a> Connection<'a> {
143142
pub fn query(&self, query: &str) -> Result<QueryResult<'a>, Error> {
144143
let conn = unsafe { (*self.conn.get()).pin_mut() };
145144
let result = ffi::connection_query(conn, ffi::StringView::new(query))?;
146-
if result.isSuccess() {
145+
if ffi::query_result_is_success(&result) {
147146
Ok(QueryResult { result })
148147
} else {
149148
Err(Error::FailedQuery(ffi::query_result_get_error_message(
@@ -186,12 +185,12 @@ impl<'a> Connection<'a> {
186185
let mut cxx_params = ffi::new_params();
187186
for (key, value) in params {
188187
let ffi_value: cxx::UniquePtr<ffi::Value> = value.try_into()?;
189-
cxx_params.pin_mut().insert(key, ffi_value);
188+
ffi::query_params_insert(cxx_params.pin_mut(), key, ffi_value);
190189
}
191190
let conn = unsafe { (*self.conn.get()).pin_mut() };
192191
let result =
193192
ffi::connection_execute(conn, prepared_statement.statement.pin_mut(), cxx_params)?;
194-
if result.isSuccess() {
193+
if ffi::query_result_is_success(&result) {
195194
Ok(QueryResult { result })
196195
} else {
197196
Err(Error::FailedQuery(ffi::query_result_get_error_message(
@@ -203,15 +202,15 @@ impl<'a> Connection<'a> {
203202
/// Interrupts all queries currently executing within this connection
204203
pub fn interrupt(&self) -> Result<(), Error> {
205204
let conn = unsafe { (*self.conn.get()).pin_mut() };
206-
Ok(conn.interrupt()?)
205+
Ok(ffi::connection_interrupt(conn)?)
207206
}
208207

209208
/// Sets the query timeout value of the current connection
210209
///
211210
/// A value of zero (the default) disables the timeout.
212211
pub fn set_query_timeout(&self, timeout_ms: u64) {
213212
let conn = unsafe { (*self.conn.get()).pin_mut() };
214-
conn.setQueryTimeOut(timeout_ms);
213+
ffi::connection_set_query_timeout(conn, timeout_ms);
215214
}
216215
}
217216

0 commit comments

Comments
 (0)