From 89cade6dab4038be96e2c793ce56669777d40110 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 28 May 2024 10:17:17 +0200 Subject: [PATCH] fix fmt, clippy, atgument naming --- build.rs | 11 +++++-- include/zenoh_commons.h | 16 +++++----- src/closures/hello_closure.rs | 11 +++++-- src/closures/matching_status_closure.rs | 14 +++++++-- src/closures/query_channel.rs | 15 +++++++--- src/closures/query_closure.rs | 21 +++++++++---- src/closures/reply_closure.rs | 12 +++++--- src/closures/response_channel.rs | 15 +++++++--- src/closures/sample_closure.rs | 9 ++++-- src/closures/zenohid_closure.rs | 5 +++- src/get.rs | 7 +++-- src/info.rs | 6 ++-- src/keyexpr.rs | 2 +- src/liveliness.rs | 8 ++--- src/payload.rs | 37 +++++++++-------------- src/publisher.rs | 2 +- src/put.rs | 2 +- src/queryable.rs | 39 +++++++++++++------------ src/querying_subscriber.rs | 2 +- src/scouting.rs | 11 +++++-- src/session.rs | 4 +-- src/subscriber.rs | 2 +- 22 files changed, 153 insertions(+), 98 deletions(-) diff --git a/build.rs b/build.rs index 065081aa5..48b01a138 100644 --- a/build.rs +++ b/build.rs @@ -881,7 +881,9 @@ pub fn create_generics_header(path_in: &str, path_out: &str) { file_out.write_all(out.as_bytes()).unwrap(); file_out.write_all("\n\n".as_bytes()).unwrap(); - let out = generate_generic_loan_to_owned_type_cpp(&vec![type_name_to_loan_func, type_name_to_loan_mut_func].concat()); + let out = generate_generic_loan_to_owned_type_cpp( + &[type_name_to_loan_func, type_name_to_loan_mut_func].concat(), + ); file_out.write_all(out.as_bytes()).unwrap(); file_out @@ -1194,7 +1196,12 @@ pub fn generate_generic_closure_cpp(macro_func: &[FunctionSignature]) -> String for func in macro_func { let return_type = &func.return_type.typename; let closure_name = &func.args[0].name; - let closure_type = func.args[0].typename.clone().without_cv().typename.replace("loaned", "owned"); + let closure_type = func.args[0] + .typename + .clone() + .without_cv() + .typename + .replace("loaned", "owned"); let arg_type = &func.args[1].typename.typename; out += "\n"; out += &format!( diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 14e8de991..66475a3ea 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -1960,7 +1960,7 @@ ZENOHC_API void z_put_options_default(struct z_put_options_t *this_); * * Returns NULL if query does not contain an attachment. */ -ZENOHC_API const struct z_loaned_bytes_t *z_query_attachment(const struct z_loaned_query_t *query); +ZENOHC_API const struct z_loaned_bytes_t *z_query_attachment(const struct z_loaned_query_t *this_); /** * Returns ``true`` if channel is valid, ``false`` if it is in gravestone state. */ @@ -2048,7 +2048,7 @@ ZENOHC_API void z_query_drop(struct z_owned_query_t *this_); /** * Gets query key expression. */ -ZENOHC_API const struct z_loaned_keyexpr_t *z_query_keyexpr(const struct z_loaned_query_t *query); +ZENOHC_API const struct z_loaned_keyexpr_t *z_query_keyexpr(const struct z_loaned_query_t *this_); /** * Borrows the query. */ @@ -2061,7 +2061,7 @@ ZENOHC_API void z_query_null(struct z_owned_query_t *this_); * Gets query value selector. */ ZENOHC_API -void z_query_parameters(const struct z_loaned_query_t *query, +void z_query_parameters(const struct z_loaned_query_t *this_, struct z_view_str_t *parameters); /** * Sends a reply to a query. @@ -2071,7 +2071,7 @@ void z_query_parameters(const struct z_loaned_query_t *query, * be called multiple times to send multiple replies to a query. The reply * will be considered complete when the Queryable callback returns. * - * @param query: The query to reply to. + * @param this_: The query to reply to. * @param key_expr: The key of this reply. * @param payload: The payload of this reply. Will be consumed. * @param options: The options of this reply. All owned fields will be consumed. @@ -2079,7 +2079,7 @@ void z_query_parameters(const struct z_loaned_query_t *query, * @return 0 in case of success, negative error code otherwise. */ ZENOHC_API -z_error_t z_query_reply(const struct z_loaned_query_t *query, +z_error_t z_query_reply(const struct z_loaned_query_t *this_, const struct z_loaned_keyexpr_t *key_expr, struct z_owned_bytes_t *payload, struct z_query_reply_options_t *options); @@ -2091,14 +2091,14 @@ z_error_t z_query_reply(const struct z_loaned_query_t *query, * be called multiple times to send multiple replies to a query. The reply * will be considered complete when the Queryable callback returns. * - * @param query: The query to reply to. + * @param this_: The query to reply to. * @param payload: The payload carrying error message. Will be consumed. * @param options: The options of this reply. All owned fields will be consumed. * * @return 0 in case of success, negative error code otherwise. */ ZENOHC_API -z_error_t z_query_reply_err(const struct z_loaned_query_t *query, +z_error_t z_query_reply_err(const struct z_loaned_query_t *this_, struct z_owned_bytes_t *payload, struct z_query_reply_err_options_t *options); /** @@ -2119,7 +2119,7 @@ ZENOHC_API enum z_query_target_t z_query_target_default(void); * Returns NULL if query does not contain a value. */ ZENOHC_API -const struct z_loaned_value_t *z_query_value(const struct z_loaned_query_t *query); +const struct z_loaned_value_t *z_query_value(const struct z_loaned_query_t *this_); /** * Returns ``true`` if queryable is valid, ``false`` otherwise. */ diff --git a/src/closures/hello_closure.rs b/src/closures/hello_closure.rs index d9c0f6d6f..11d01a5d4 100644 --- a/src/closures/hello_closure.rs +++ b/src/closures/hello_closure.rs @@ -1,6 +1,9 @@ use std::mem::MaybeUninit; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_hello_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_loaned_hello_t, +}; use libc::c_void; /// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: @@ -106,6 +109,8 @@ pub extern "C" fn z_closure_hello_check(this: &z_owned_closure_hello_t) -> bool /// Borrows closure. #[no_mangle] -pub extern "C" fn z_closure_hello_loan(closure: &z_owned_closure_hello_t) -> &z_loaned_closure_hello_t { +pub extern "C" fn z_closure_hello_loan( + closure: &z_owned_closure_hello_t, +) -> &z_loaned_closure_hello_t { closure.transmute_handle() -} \ No newline at end of file +} diff --git a/src/closures/matching_status_closure.rs b/src/closures/matching_status_closure.rs index cd0057172..a7e2a1607 100644 --- a/src/closures/matching_status_closure.rs +++ b/src/closures/matching_status_closure.rs @@ -2,7 +2,10 @@ use std::mem::MaybeUninit; use libc::c_void; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, zcu_matching_status_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + zcu_matching_status_t, +}; /// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: /// /// Closures are not guaranteed not to be called concurrently. @@ -27,7 +30,10 @@ pub struct zcu_loaned_closure_matching_status_t { _0: [usize; 3], } -decl_transmute_handle!(zcu_owned_closure_matching_status_t, zcu_loaned_closure_matching_status_t); +decl_transmute_handle!( + zcu_owned_closure_matching_status_t, + zcu_loaned_closure_matching_status_t +); impl zcu_owned_closure_matching_status_t { pub fn empty() -> Self { @@ -112,6 +118,8 @@ impl From for zcu_owned_closure_matching_statu /// Borrows closure. #[no_mangle] -pub extern "C" fn zcu_closure_matching_status_loan(closure: &zcu_owned_closure_matching_status_t) -> &zcu_loaned_closure_matching_status_t { +pub extern "C" fn zcu_closure_matching_status_loan( + closure: &zcu_owned_closure_matching_status_t, +) -> &zcu_loaned_closure_matching_status_t { closure.transmute_handle() } diff --git a/src/closures/query_channel.rs b/src/closures/query_channel.rs index 7ac90bd59..45a990eca 100644 --- a/src/closures/query_channel.rs +++ b/src/closures/query_channel.rs @@ -1,5 +1,7 @@ use crate::{ - transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_closure_query_drop, z_loaned_query_t, z_owned_closure_query_t, z_owned_query_t, z_query_clone, z_query_null + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_closure_query_drop, z_loaned_query_t, z_owned_closure_query_t, z_owned_query_t, + z_query_clone, z_query_null, }; use libc::c_void; use std::{ @@ -33,7 +35,10 @@ pub struct z_loaned_query_channel_closure_t { _0: [usize; 3], } -decl_transmute_handle!(z_owned_query_channel_closure_t, z_loaned_query_channel_closure_t); +decl_transmute_handle!( + z_owned_query_channel_closure_t, + z_loaned_query_channel_closure_t +); /// A pair of send / receive ends of channel. #[repr(C)] @@ -246,6 +251,8 @@ impl) -> bool> From for z_owned_query /// Borrows closure. #[no_mangle] -pub extern "C" fn z_query_channel_closure_loan(closure: &z_owned_query_channel_closure_t) -> &z_loaned_query_channel_closure_t { +pub extern "C" fn z_query_channel_closure_loan( + closure: &z_owned_query_channel_closure_t, +) -> &z_loaned_query_channel_closure_t { closure.transmute_handle() -} \ No newline at end of file +} diff --git a/src/closures/query_closure.rs b/src/closures/query_closure.rs index d2ad25a13..ed6c8b920 100644 --- a/src/closures/query_closure.rs +++ b/src/closures/query_closure.rs @@ -1,6 +1,9 @@ use std::mem::MaybeUninit; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_query_t, z_owned_query_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_loaned_query_t, z_owned_query_t, +}; use libc::c_void; /// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: /// @@ -126,7 +129,10 @@ pub struct z_owned_closure_owned_query_t { pub struct z_loaned_closure_owned_query_t { _0: [usize; 3], } -decl_transmute_handle!(z_owned_closure_owned_query_t, z_loaned_closure_owned_query_t); +decl_transmute_handle!( + z_owned_closure_owned_query_t, + z_loaned_closure_owned_query_t +); impl z_owned_closure_owned_query_t { pub fn empty() -> Self { @@ -189,15 +195,18 @@ impl From for z_owned_closure_owned_query_t { } } - /// Borrows closure. #[no_mangle] -pub extern "C" fn z_closure_query_loan(closure: &z_owned_closure_query_t) -> &z_loaned_closure_query_t { +pub extern "C" fn z_closure_query_loan( + closure: &z_owned_closure_query_t, +) -> &z_loaned_closure_query_t { closure.transmute_handle() } /// Borrows closure. #[no_mangle] -pub extern "C" fn z_closure_owned_query_loan(closure: &z_owned_closure_owned_query_t) -> &z_loaned_closure_owned_query_t { +pub extern "C" fn z_closure_owned_query_loan( + closure: &z_owned_closure_owned_query_t, +) -> &z_loaned_closure_owned_query_t { closure.transmute_handle() -} \ No newline at end of file +} diff --git a/src/closures/reply_closure.rs b/src/closures/reply_closure.rs index 830084e82..9c95ceaed 100644 --- a/src/closures/reply_closure.rs +++ b/src/closures/reply_closure.rs @@ -1,6 +1,9 @@ use std::mem::MaybeUninit; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_reply_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_loaned_reply_t, +}; use libc::c_void; /// A structure that contains all the elements for stateful, memory-leak-free callbacks. /// @@ -102,9 +105,10 @@ impl From for z_owned_closure_reply_t { } } - /// Borrows closure. #[no_mangle] -pub extern "C" fn z_closure_reply_loan(closure: &z_owned_closure_reply_t) -> &z_loaned_closure_reply_t { +pub extern "C" fn z_closure_reply_loan( + closure: &z_owned_closure_reply_t, +) -> &z_loaned_closure_reply_t { closure.transmute_handle() -} \ No newline at end of file +} diff --git a/src/closures/response_channel.rs b/src/closures/response_channel.rs index 97ed86004..647a4e7fa 100644 --- a/src/closures/response_channel.rs +++ b/src/closures/response_channel.rs @@ -1,5 +1,7 @@ use crate::{ - transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_closure_reply_drop, z_loaned_reply_t, z_owned_closure_reply_t, z_owned_reply_t, z_reply_clone, z_reply_null + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_closure_reply_drop, z_loaned_reply_t, z_owned_closure_reply_t, z_owned_reply_t, + z_reply_clone, z_reply_null, }; use libc::c_void; use std::{ @@ -31,7 +33,10 @@ pub struct z_owned_reply_channel_closure_t { pub struct z_loaned_reply_channel_closure_t { _0: [usize; 3], } -decl_transmute_handle!(z_owned_reply_channel_closure_t, z_loaned_reply_channel_closure_t); +decl_transmute_handle!( + z_owned_reply_channel_closure_t, + z_loaned_reply_channel_closure_t +); /// A pair of send / receive ends of channel. #[repr(C)] @@ -245,6 +250,8 @@ impl) -> bool> From for z_owned_reply /// Borrows closure. #[no_mangle] -pub extern "C" fn z_reply_channel_closure_loan(closure: &z_owned_reply_channel_closure_t) -> &z_loaned_reply_channel_closure_t { +pub extern "C" fn z_reply_channel_closure_loan( + closure: &z_owned_reply_channel_closure_t, +) -> &z_loaned_reply_channel_closure_t { closure.transmute_handle() -} \ No newline at end of file +} diff --git a/src/closures/sample_closure.rs b/src/closures/sample_closure.rs index a5a08dd24..45b47cb75 100644 --- a/src/closures/sample_closure.rs +++ b/src/closures/sample_closure.rs @@ -1,6 +1,9 @@ use std::mem::MaybeUninit; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_sample_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_loaned_sample_t, +}; use libc::c_void; /// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks. /// @@ -104,6 +107,8 @@ impl From for z_owned_closure_sample_t { /// Borrows closure. #[no_mangle] -pub extern "C" fn z_closure_sample_loan(closure: &z_owned_closure_sample_t) -> &z_loaned_closure_sample_t { +pub extern "C" fn z_closure_sample_loan( + closure: &z_owned_closure_sample_t, +) -> &z_loaned_closure_sample_t { closure.transmute_handle() } diff --git a/src/closures/zenohid_closure.rs b/src/closures/zenohid_closure.rs index 7efb46ca2..b69aaeb86 100644 --- a/src/closures/zenohid_closure.rs +++ b/src/closures/zenohid_closure.rs @@ -2,7 +2,10 @@ use std::mem::MaybeUninit; use libc::c_void; -use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_id_t}; +use crate::{ + transmute::{TransmuteFromHandle, TransmuteIntoHandle}, + z_id_t, +}; /// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks: /// /// Closures are not guaranteed not to be called concurrently. diff --git a/src/get.rs b/src/get.rs index 172b61586..ec2d01f44 100644 --- a/src/get.rs +++ b/src/get.rs @@ -40,7 +40,7 @@ use crate::z_query_target_t; use crate::{ z_closure_reply_call, z_loaned_keyexpr_t, z_loaned_session_t, z_owned_closure_reply_t, }; -use::zenoh::core::Wait; +use ::zenoh::core::Wait; pub use crate::opaque_types::z_owned_reply_t; decl_transmute_owned!(Option, z_owned_reply_t); @@ -175,8 +175,9 @@ pub unsafe extern "C" fn z_get( } } match get - .callback(move |response| - z_closure_reply_call(z_closure_reply_loan(&closure), response.transmute_handle())) + .callback(move |response| { + z_closure_reply_call(z_closure_reply_loan(&closure), response.transmute_handle()) + }) .wait() { Ok(()) => errors::Z_OK, diff --git a/src/info.rs b/src/info.rs index f616005eb..cdc7866b5 100644 --- a/src/info.rs +++ b/src/info.rs @@ -12,11 +12,13 @@ // ZettaScale Zenoh team, // use crate::transmute::{TransmuteCopy, TransmuteFromHandle}; -use crate::{errors, z_closure_zid_call, z_closure_zid_loan, z_loaned_session_t, z_owned_closure_zid_t}; +use crate::{ + errors, z_closure_zid_call, z_closure_zid_loan, z_loaned_session_t, z_owned_closure_zid_t, +}; use std::mem::MaybeUninit; use zenoh::config::ZenohId; -use zenoh::session::SessionDeclarations; use zenoh::core::Wait; +use zenoh::session::SessionDeclarations; pub use crate::opaque_types::z_id_t; decl_transmute_copy!(ZenohId, z_id_t); diff --git a/src/keyexpr.rs b/src/keyexpr.rs index 144179a11..2de011e41 100644 --- a/src/keyexpr.rs +++ b/src/keyexpr.rs @@ -27,11 +27,11 @@ use crate::z_view_str_from_substring; use crate::z_view_str_t; use libc::c_char; use std::error::Error; +use zenoh::core::Wait; use zenoh::key_expr::SetIntersectionLevel; use zenoh::prelude::keyexpr; use zenoh::prelude::KeyExpr; use zenoh_protocol::core::key_expr::canon::Canonizable; -use zenoh::core::Wait; pub use crate::opaque_types::z_owned_keyexpr_t; pub use crate::opaque_types::z_view_keyexpr_t; diff --git a/src/liveliness.rs b/src/liveliness.rs index 451337983..35cea152a 100644 --- a/src/liveliness.rs +++ b/src/liveliness.rs @@ -19,13 +19,13 @@ use zenoh::{ }; use crate::transmute::TransmuteIntoHandle; -use crate::{z_closure_reply_loan, z_closure_sample_loan}; use crate::{ errors, transmute::{Inplace, TransmuteFromHandle, TransmuteRef, TransmuteUninitPtr}, z_closure_reply_call, z_closure_sample_call, z_loaned_keyexpr_t, z_loaned_session_t, z_owned_closure_reply_t, z_owned_closure_sample_t, z_owned_subscriber_t, }; +use crate::{z_closure_reply_loan, z_closure_sample_loan}; use zenoh::core::Wait; use crate::opaque_types::zc_loaned_liveliness_token_t; @@ -202,9 +202,9 @@ pub extern "C" fn zc_liveliness_get( let key_expr = key_expr.transmute_ref(); let callback = core::mem::replace(callback, z_owned_closure_reply_t::empty()); let liveliness: Liveliness<'static> = session.liveliness(); - let mut builder = liveliness - .get(key_expr) - .callback(move |response| z_closure_reply_call(z_closure_reply_loan(&callback), response.transmute_handle())); + let mut builder = liveliness.get(key_expr).callback(move |response| { + z_closure_reply_call(z_closure_reply_loan(&callback), response.transmute_handle()) + }); if let Some(options) = options { builder = builder.timeout(core::time::Duration::from_millis(options.timeout_ms as u64)); } diff --git a/src/payload.rs b/src/payload.rs index 8f427a007..a139534a3 100644 --- a/src/payload.rs +++ b/src/payload.rs @@ -255,18 +255,18 @@ pub extern "C" fn z_bytes_encode_from_pair( this: *mut MaybeUninit, first: &mut z_owned_bytes_t, second: &mut z_owned_bytes_t, -) -> z_error_t{ +) -> z_error_t { let first = match first.transmute_mut().extract() { Some(z) => z, None => return Z_EINVAL, }; let second = match second.transmute_mut().extract() { Some(z) => z, - None => return Z_EINVAL , + None => return Z_EINVAL, }; let b = ZBytes::serialize((first, second)); Inplace::init(this.transmute_uninit_ptr(), Some(b)); - return Z_OK; + Z_OK } /// Decodes into a pair of `z_owned_bytes` objects. @@ -281,20 +281,17 @@ pub extern "C" fn z_bytes_decode_into_pair( Ok((a, b)) => { Inplace::init(first.transmute_uninit_ptr(), Some(a)); Inplace::init(second.transmute_uninit_ptr(), Some(b)); - return Z_OK; - }, + Z_OK + } Err(e) => { log::error!("Failed to decode the payload: {}", e); - return Z_EPARSE; + Z_EPARSE } - }; + } } struct ZBytesInIterator { - body: extern "C" fn( - data: &mut MaybeUninit, - context: *mut c_void, - ), + body: extern "C" fn(data: &mut MaybeUninit, context: *mut c_void), context: *mut c_void, } @@ -309,20 +306,15 @@ impl Iterator for ZBytesInIterator { } } - - /// Constructs payload from an iterator to `z_owned_bytes_t`. /// @param this_: An uninitialized location in memery for `z_owned_bytes_t` will be constructed. -/// @param iterator_body: Iterator body function, providing data items. Returning NULL +/// @param iterator_body: Iterator body function, providing data items. Returning NULL /// @param context: Arbitrary context that will be passed to iterator_body. /// @return 0 in case of success, negative error code otherwise. #[no_mangle] pub extern "C" fn z_bytes_encode_from_iter( this: *mut MaybeUninit, - iterator_body: extern "C" fn( - data: &mut MaybeUninit, - context: *mut c_void, - ), + iterator_body: extern "C" fn(data: &mut MaybeUninit, context: *mut c_void), context: *mut c_void, ) -> z_error_t { let it = ZBytesInIterator { @@ -332,7 +324,7 @@ pub extern "C" fn z_bytes_encode_from_iter( let b = ZBytes::from_iter(it); Inplace::init(this.transmute_uninit_ptr(), Some(b)); - return Z_OK; + Z_OK } /// Decodes payload into an iterator to `z_loaned_bytes_t`. @@ -343,10 +335,7 @@ pub extern "C" fn z_bytes_encode_from_iter( #[no_mangle] pub extern "C" fn z_bytes_decode_into_iter( this: &z_loaned_bytes_t, - iterator_body: extern "C" fn( - data: &z_loaned_bytes_t, - context: *mut c_void, - ) -> z_error_t, + iterator_body: extern "C" fn(data: &z_loaned_bytes_t, context: *mut c_void) -> z_error_t, context: *mut c_void, ) -> z_error_t { let mut res = Z_OK; @@ -358,7 +347,7 @@ pub extern "C" fn z_bytes_decode_into_iter( } } - return res; + res } pub use crate::opaque_types::z_owned_bytes_reader_t; diff --git a/src/publisher.rs b/src/publisher.rs index 49d950009..42303932f 100644 --- a/src/publisher.rs +++ b/src/publisher.rs @@ -25,6 +25,7 @@ use crate::zcu_closure_matching_status_loan; use crate::zcu_owned_closure_matching_status_t; use std::mem::MaybeUninit; use std::ptr; +use zenoh::core::Wait; use zenoh::handlers::DefaultHandler; use zenoh::prelude::SessionDeclarations; use zenoh::publication::CongestionControl; @@ -32,7 +33,6 @@ use zenoh::sample::QoSBuilderTrait; use zenoh::sample::SampleBuilderTrait; use zenoh::sample::ValueBuilderTrait; use zenoh::{prelude::Priority, publication::MatchingListener, publication::Publisher}; -use zenoh::core::Wait; use crate::{ z_congestion_control_t, z_loaned_keyexpr_t, z_loaned_session_t, z_owned_bytes_t, z_priority_t, diff --git a/src/put.rs b/src/put.rs index bd05e47b1..829d8eb2b 100644 --- a/src/put.rs +++ b/src/put.rs @@ -21,12 +21,12 @@ use crate::transmute::TransmuteFromHandle; use crate::transmute::TransmuteRef; use crate::z_loaned_session_t; use crate::z_owned_bytes_t; +use zenoh::core::Wait; use zenoh::prelude::Priority; use zenoh::publication::CongestionControl; use zenoh::sample::QoSBuilderTrait; use zenoh::sample::SampleBuilderTrait; use zenoh::sample::ValueBuilderTrait; -use zenoh::core::Wait; /// Options passed to the `z_put()` function. #[repr(C)] diff --git a/src/queryable.rs b/src/queryable.rs index 395cf887c..8e4ce100a 100644 --- a/src/queryable.rs +++ b/src/queryable.rs @@ -16,16 +16,18 @@ use crate::transmute::{ TransmuteUninitPtr, }; use crate::{ - errors, z_closure_query_call, z_closure_query_loan, z_loaned_bytes_t, z_loaned_keyexpr_t, z_loaned_session_t, z_loaned_value_t, z_owned_bytes_t, z_owned_closure_query_t, z_owned_encoding_t, z_view_str_from_substring, z_view_str_t + errors, z_closure_query_call, z_closure_query_loan, z_loaned_bytes_t, z_loaned_keyexpr_t, + z_loaned_session_t, z_loaned_value_t, z_owned_bytes_t, z_owned_closure_query_t, + z_owned_encoding_t, z_view_str_from_substring, z_view_str_t, }; use std::mem::MaybeUninit; use std::ptr::null_mut; +use zenoh::core::Wait; use zenoh::encoding::Encoding; use zenoh::prelude::SessionDeclarations; use zenoh::prelude::{Query, Queryable}; use zenoh::sample::{SampleBuilderTrait, ValueBuilderTrait}; use zenoh::value::Value; -use zenoh::core::Wait; pub use crate::opaque_types::z_owned_queryable_t; decl_transmute_owned!(Option>, z_owned_queryable_t); @@ -169,7 +171,9 @@ pub extern "C" fn z_declare_queryable( builder = builder.complete(options.complete); } let queryable = builder - .callback(move |query| z_closure_query_call(z_closure_query_loan(&closure), query.transmute_handle())) + .callback(move |query| { + z_closure_query_call(z_closure_query_loan(&closure), query.transmute_handle()) + }) .wait(); match queryable { Ok(q) => { @@ -218,7 +222,7 @@ pub extern "C" fn z_queryable_check(this: &z_owned_queryable_t) -> bool { /// be called multiple times to send multiple replies to a query. The reply /// will be considered complete when the Queryable callback returns. /// -/// @param query: The query to reply to. +/// @param this_: The query to reply to. /// @param key_expr: The key of this reply. /// @param payload: The payload of this reply. Will be consumed. /// @param options: The options of this reply. All owned fields will be consumed. @@ -227,12 +231,12 @@ pub extern "C" fn z_queryable_check(this: &z_owned_queryable_t) -> bool { #[allow(clippy::missing_safety_doc)] #[no_mangle] pub unsafe extern "C" fn z_query_reply( - query: &z_loaned_query_t, + this: &z_loaned_query_t, key_expr: &z_loaned_keyexpr_t, payload: &mut z_owned_bytes_t, options: Option<&mut z_query_reply_options_t>, ) -> errors::z_error_t { - let query = query.transmute_ref(); + let query = this.transmute_ref(); let key_expr = key_expr.transmute_ref(); let payload = match payload.transmute_mut().extract() { @@ -269,7 +273,7 @@ pub unsafe extern "C" fn z_query_reply( /// be called multiple times to send multiple replies to a query. The reply /// will be considered complete when the Queryable callback returns. /// -/// @param query: The query to reply to. +/// @param this_: The query to reply to. /// @param payload: The payload carrying error message. Will be consumed. /// @param options: The options of this reply. All owned fields will be consumed. /// @@ -277,11 +281,11 @@ pub unsafe extern "C" fn z_query_reply( #[allow(clippy::missing_safety_doc)] #[no_mangle] pub unsafe extern "C" fn z_query_reply_err( - query: &z_loaned_query_t, + this: &z_loaned_query_t, payload: &mut z_owned_bytes_t, options: Option<&mut z_query_reply_err_options_t>, ) -> errors::z_error_t { - let query = query.transmute_ref(); + let query = this.transmute_ref(); let payload = match payload.transmute_mut().extract() { Some(p) => p, @@ -309,18 +313,18 @@ pub unsafe extern "C" fn z_query_reply_err( /// Gets query key expression. #[allow(clippy::missing_safety_doc)] #[no_mangle] -pub extern "C" fn z_query_keyexpr(query: &z_loaned_query_t) -> &z_loaned_keyexpr_t { - query.transmute_ref().key_expr().transmute_handle() +pub extern "C" fn z_query_keyexpr(this: &z_loaned_query_t) -> &z_loaned_keyexpr_t { + this.transmute_ref().key_expr().transmute_handle() } /// Gets query value selector. #[allow(clippy::missing_safety_doc)] #[no_mangle] pub unsafe extern "C" fn z_query_parameters( - query: &z_loaned_query_t, + this: &z_loaned_query_t, parameters: *mut MaybeUninit, ) { - let query = query.transmute_ref(); + let query = this.transmute_ref(); let params = query.parameters().as_str(); unsafe { z_view_str_from_substring(parameters, params.as_ptr() as _, params.len()) }; } @@ -329,17 +333,16 @@ pub unsafe extern "C" fn z_query_parameters( /// /// Returns NULL if query does not contain a value. #[no_mangle] -pub extern "C" fn z_query_value(query: &z_loaned_query_t) -> Option<&z_loaned_value_t> { - query.transmute_ref().value().map(|v| v.transmute_handle()) +pub extern "C" fn z_query_value(this: &z_loaned_query_t) -> Option<&z_loaned_value_t> { + this.transmute_ref().value().map(|v| v.transmute_handle()) } /// Gets query attachment. /// /// Returns NULL if query does not contain an attachment. #[no_mangle] -pub extern "C" fn z_query_attachment(query: &z_loaned_query_t) -> Option<&z_loaned_bytes_t> { - query - .transmute_ref() +pub extern "C" fn z_query_attachment(this: &z_loaned_query_t) -> Option<&z_loaned_bytes_t> { + this.transmute_ref() .attachment() .map(|a| a.transmute_handle()) } diff --git a/src/querying_subscriber.rs b/src/querying_subscriber.rs index df92e375e..93bf86db1 100644 --- a/src/querying_subscriber.rs +++ b/src/querying_subscriber.rs @@ -31,11 +31,11 @@ use crate::{ z_query_consolidation_t, z_query_target_default, z_query_target_t, zcu_locality_default, zcu_locality_t, zcu_reply_keyexpr_default, zcu_reply_keyexpr_t, }; +use zenoh::core::Wait; use zenoh::prelude::SessionDeclarations; use zenoh::session::Session; use zenoh::subscriber::Reliability; use zenoh_ext::*; -use zenoh::core::Wait; use crate::opaque_types::ze_loaned_querying_subscriber_t; use crate::opaque_types::ze_owned_querying_subscriber_t; diff --git a/src/scouting.rs b/src/scouting.rs index b20f8f314..261c98b00 100644 --- a/src/scouting.rs +++ b/src/scouting.rs @@ -12,10 +12,13 @@ // ZettaScale Zenoh team, // use crate::{ - errors::{self, Z_OK}, transmute::{ + errors::{self, Z_OK}, + transmute::{ unwrap_ref_unchecked, Inplace, TransmuteCopy, TransmuteFromHandle, TransmuteIntoHandle, TransmuteRef, TransmuteUninitPtr, - }, z_closure_hello_call, z_closure_hello_loan, z_id_t, z_owned_closure_hello_t, z_owned_config_t, z_owned_str_array_t, z_view_str_t, zc_init_logger, CSlice, ZVector + }, + z_closure_hello_call, z_closure_hello_loan, z_id_t, z_owned_closure_hello_t, z_owned_config_t, + z_owned_str_array_t, z_view_str_t, zc_init_logger, CSlice, ZVector, }; use async_std::task; use libc::c_ulong; @@ -165,7 +168,9 @@ pub extern "C" fn z_scout( task::block_on(async move { let scout = zenoh::scout(what, config) - .callback(move |h| z_closure_hello_call(z_closure_hello_loan(&closure), h.transmute_handle())) + .callback(move |h| { + z_closure_hello_call(z_closure_hello_loan(&closure), h.transmute_handle()) + }) .await .unwrap(); async_std::task::sleep(std::time::Duration::from_millis(timeout)).await; diff --git a/src/session.rs b/src/session.rs index 154b9b5b3..dcbd49683 100644 --- a/src/session.rs +++ b/src/session.rs @@ -19,8 +19,8 @@ use crate::transmute::{ use crate::{errors, z_owned_config_t, zc_init_logger}; use std::mem::MaybeUninit; use std::sync::Arc; -use zenoh::session::Session; use zenoh::core::Wait; +use zenoh::session::Session; use crate::opaque_types::z_owned_session_t; decl_transmute_owned!(Option>, z_owned_session_t); @@ -105,7 +105,7 @@ pub extern "C" fn z_close(this: &mut z_owned_session_t) -> errors::z_error_t { Err(e) => { log::error!("Error closing session: {}", e); errors::Z_EGENERIC - }, + } Ok(_) => errors::Z_OK, } } diff --git a/src/subscriber.rs b/src/subscriber.rs index 8b7b901b2..d5cb02894 100644 --- a/src/subscriber.rs +++ b/src/subscriber.rs @@ -26,10 +26,10 @@ use crate::z_closure_sample_call; use crate::z_closure_sample_loan; use crate::z_loaned_session_t; use crate::z_owned_closure_sample_t; +use zenoh::core::Wait; use zenoh::prelude::SessionDeclarations; use zenoh::subscriber::Reliability; use zenoh::subscriber::Subscriber; -use zenoh::core::Wait; /// The subscription reliability. #[allow(non_camel_case_types, clippy::upper_case_acronyms)]