From 892dd4ab48f864406179f753e739138d913fa5fc Mon Sep 17 00:00:00 2001 From: Martin Dahl Date: Mon, 26 Jun 2023 13:33:41 +0200 Subject: [PATCH] rustfmt --- r2r/build.rs | 9 ++---- r2r/examples/action_client.rs | 6 +--- r2r/examples/action_server.rs | 11 ++----- r2r/examples/client.rs | 3 +- r2r/examples/parameters.rs | 5 +--- r2r/examples/service.rs | 5 +--- r2r/examples/untyped_client.rs | 3 +- r2r/examples/wall_timer.rs | 6 +--- r2r/src/action_clients.rs | 30 ++++++++----------- r2r/src/action_clients_untyped.rs | 17 +++++------ r2r/src/action_servers.rs | 30 +++++-------------- r2r/src/clients.rs | 16 +++++----- r2r/src/clocks.rs | 6 +--- r2r/src/msg_types.rs | 25 +++++----------- r2r/src/nodes.rs | 50 ++++++++----------------------- r2r/src/publishers.rs | 26 +++++----------- r2r/src/qos.rs | 3 +- r2r/src/services.rs | 14 ++------- r2r/src/subscribers.rs | 18 ++--------- r2r/src/utils.rs | 8 +---- r2r_actions/build.rs | 6 +--- r2r_common/src/lib.rs | 5 +--- r2r_msg_gen/build.rs | 16 ++-------- r2r_msg_gen/src/lib.rs | 12 ++------ r2r_rcl/build.rs | 6 +--- rustfmt.toml | 2 ++ 26 files changed, 92 insertions(+), 246 deletions(-) diff --git a/r2r/build.rs b/r2r/build.rs index 139655d..cf38ccc 100644 --- a/r2r/build.rs +++ b/r2r/build.rs @@ -1,11 +1,10 @@ - #[cfg(not(feature = "doc-only"))] use { quote::{format_ident, quote}, rayon::prelude::*, + std::fmt, std::fs::{File, OpenOptions}, std::io::{self, prelude::*, BufWriter}, - std::fmt, }; use std::path::{Path, PathBuf}; @@ -283,11 +282,7 @@ fn generate_bindings(bindgen_dir: &Path) { } fn copy_files(src_dir: &Path, tgt_dir: &Path) { - eprintln!( - "Copy files from '{}' to '{}'", - src_dir.display(), - tgt_dir.display() - ); + eprintln!("Copy files from '{}' to '{}'", src_dir.display(), tgt_dir.display()); let src_list_file = src_dir.join(LIST_FILENAME); let tgt_list_file = tgt_dir.join(LIST_FILENAME); diff --git a/r2r/examples/action_client.rs b/r2r/examples/action_client.rs index b9d06cc..9d47c61 100644 --- a/r2r/examples/action_client.rs +++ b/r2r/examples/action_client.rs @@ -44,11 +44,7 @@ fn main() -> Result<(), Box> { let nested_task_done = nested_task_done.clone(); let nested_goal = nested_goal.clone(); async move { - println!( - "new feedback msg {:?} -- {:?}", - msg, - nested_goal.get_status() - ); + println!("new feedback msg {:?} -- {:?}", msg, nested_goal.get_status()); // 50/50 that cancel the goal before it finishes. if msg.sequence.len() == 4 && rand::random::() { diff --git a/r2r/examples/action_server.rs b/r2r/examples/action_server.rs index 358dc56..3917521 100644 --- a/r2r/examples/action_server.rs +++ b/r2r/examples/action_server.rs @@ -8,8 +8,7 @@ use std::sync::{Arc, Mutex}; // main goal handling routine. async fn run_goal( - node: Arc>, - g: r2r::ActionServerGoal, + node: Arc>, g: r2r::ActionServerGoal, ) -> Fibonacci::Result { let mut timer = node // local timer, will be dropped after this request is processed. .lock() @@ -38,17 +37,13 @@ async fn run_goal( } async fn fibonacci_server( - spawner: LocalSpawner, - node: Arc>, + spawner: LocalSpawner, node: Arc>, mut requests: impl Stream> + Unpin, ) { loop { match requests.next().await { Some(req) => { - println!( - "Got goal request with order {}, goal id: {}", - req.goal.order, req.uuid - ); + println!("Got goal request with order {}, goal id: {}", req.goal.order, req.uuid); // 1/4 chance that we reject the goal for testing. if rand::random::() && rand::random::() { println!("rejecting goal"); diff --git a/r2r/examples/client.rs b/r2r/examples/client.rs index d3259d2..7b14694 100644 --- a/r2r/examples/client.rs +++ b/r2r/examples/client.rs @@ -7,8 +7,7 @@ use std::io::Write; use r2r::example_interfaces::srv::AddTwoInts; async fn requester_task( - node_available: impl Future>, - c: r2r::Client, + node_available: impl Future>, c: r2r::Client, ) -> Result<(), Box> { let mut x: i64 = 0; println!("waiting for service..."); diff --git a/r2r/examples/parameters.rs b/r2r/examples/parameters.rs index c411cb4..d40487f 100644 --- a/r2r/examples/parameters.rs +++ b/r2r/examples/parameters.rs @@ -37,10 +37,7 @@ fn main() -> Result<(), Box> { })?; println!("node name: {}", node.name()?); - println!( - "node fully qualified name: {}", - node.fully_qualified_name()? - ); + println!("node fully qualified name: {}", node.fully_qualified_name()?); println!("node namespace: {}", node.namespace()?); // print all params every 5 seconds. diff --git a/r2r/examples/service.rs b/r2r/examples/service.rs index 7f72ad7..abb4499 100644 --- a/r2r/examples/service.rs +++ b/r2r/examples/service.rs @@ -78,10 +78,7 @@ fn main() -> Result<(), Box> { spawner.spawn_local(async move { loop { let elapsed = timer.tick().await.expect("could not tick"); - println!( - "doing other async work, {}ms since last call", - elapsed.as_millis() - ); + println!("doing other async work, {}ms since last call", elapsed.as_millis()); } })?; diff --git a/r2r/examples/untyped_client.rs b/r2r/examples/untyped_client.rs index 01ce621..20df39a 100644 --- a/r2r/examples/untyped_client.rs +++ b/r2r/examples/untyped_client.rs @@ -3,8 +3,7 @@ use futures::task::LocalSpawnExt; use futures::Future; async fn requester_task( - node_available: impl Future>, - c: r2r::ClientUntyped, + node_available: impl Future>, c: r2r::ClientUntyped, ) -> Result<(), Box> { let mut x: i64 = 0; println!("waiting for service..."); diff --git a/r2r/examples/wall_timer.rs b/r2r/examples/wall_timer.rs index 1358f34..bba231f 100644 --- a/r2r/examples/wall_timer.rs +++ b/r2r/examples/wall_timer.rs @@ -8,11 +8,7 @@ async fn timer_task(mut t: r2r::Timer) -> Result<(), Box> let mut x: i32 = 0; loop { let elapsed = t.tick().await?; - println!( - "timer called ({}), {}us since last call", - x, - elapsed.as_micros() - ); + println!("timer called ({}), {}us since last call", x, elapsed.as_micros()); x += 1; if x == 10 { diff --git a/r2r/src/action_clients.rs b/r2r/src/action_clients.rs index cfa4fe1..f2d8209 100644 --- a/r2r/src/action_clients.rs +++ b/r2r/src/action_clients.rs @@ -86,8 +86,7 @@ where /// - A new future for the eventual result. /// - A stream of feedback messages. pub fn send_goal_request( - &self, - goal: T::Goal, + &self, goal: T::Goal, ) -> Result< impl Future< Output = Result<( @@ -219,8 +218,7 @@ where } pub fn send_cancel_request( - &mut self, - goal: &uuid::Uuid, + &mut self, goal: &uuid::Uuid, ) -> Result>> where T: WrappedActionTypeSupport, @@ -326,7 +324,8 @@ where .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } @@ -364,7 +363,8 @@ where .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } @@ -453,7 +453,8 @@ where .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } @@ -513,9 +514,7 @@ where } pub fn create_action_client_helper( - node: &mut rcl_node_t, - action_name: &str, - action_ts: *const rosidl_action_type_support_t, + node: &mut rcl_node_t, action_name: &str, action_ts: *const rosidl_action_type_support_t, ) -> Result { let mut client_handle = unsafe { rcl_action_get_zero_initialized_client() }; let action_name_c_string = @@ -539,12 +538,8 @@ pub fn create_action_client_helper( } pub fn action_client_get_num_waits( - rcl_handle: &rcl_action_client_t, - num_subs: &mut usize, - num_gc: &mut usize, - num_timers: &mut usize, - num_clients: &mut usize, - num_services: &mut usize, + rcl_handle: &rcl_action_client_t, num_subs: &mut usize, num_gc: &mut usize, + num_timers: &mut usize, num_clients: &mut usize, num_services: &mut usize, ) -> Result<()> { unsafe { let result = rcl_action_client_wait_set_get_num_entities( @@ -581,8 +576,7 @@ where } pub fn action_server_available_helper( - node: &rcl_node_t, - client: &rcl_action_client_t, + node: &rcl_node_t, client: &rcl_action_client_t, ) -> Result { let mut avail = false; let result = unsafe { rcl_action_server_is_available(node, client, &mut avail) }; diff --git a/r2r/src/action_clients_untyped.rs b/r2r/src/action_clients_untyped.rs index 56f7557..33c86ec 100644 --- a/r2r/src/action_clients_untyped.rs +++ b/r2r/src/action_clients_untyped.rs @@ -165,10 +165,7 @@ pub fn make_action_client_untyped( ActionClientUntyped { client } } -pub type ResultSender = ( - uuid::Uuid, - oneshot::Sender<(GoalStatus, Result)>, -); +pub type ResultSender = (uuid::Uuid, oneshot::Sender<(GoalStatus, Result)>); pub struct WrappedActionClientUntyped { pub action_type_support: UntypedActionSupport, pub rcl_handle: rcl_action_client_t, @@ -189,8 +186,7 @@ impl WrappedActionClientUntyped { } pub fn send_cancel_request( - &mut self, - goal: &uuid::Uuid, + &mut self, goal: &uuid::Uuid, ) -> Result>> { let msg = action_msgs::srv::CancelGoal::Request { goal_info: action_msgs::msg::GoalInfo { @@ -288,7 +284,8 @@ impl ActionClient_ for WrappedActionClientUntyped { .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } @@ -326,7 +323,8 @@ impl ActionClient_ for WrappedActionClientUntyped { .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } @@ -412,7 +410,8 @@ impl ActionClient_ for WrappedActionClientUntyped { .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } diff --git a/r2r/src/action_servers.rs b/r2r/src/action_servers.rs index e5dab13..b957c85 100644 --- a/r2r/src/action_servers.rs +++ b/r2r/src/action_servers.rs @@ -23,9 +23,7 @@ pub trait ActionServer_ { fn handle_goal_expired(&mut self); fn publish_status(&self); fn set_goal_state( - &mut self, - uuid: &uuid::Uuid, - new_state: rcl_action_goal_event_t, + &mut self, uuid: &uuid::Uuid, new_state: rcl_action_goal_event_t, ) -> Result<()>; fn add_result(&mut self, uuid: uuid::Uuid, msg: Box); fn cancel_goal(&mut self, uuid: &uuid::Uuid); @@ -77,10 +75,7 @@ where /// Returns a handle to the goal and a stream on which cancel requests can be received. pub fn accept( mut self, - ) -> Result<( - ActionServerGoal, - impl Stream + Unpin, - )> { + ) -> Result<(ActionServerGoal, impl Stream + Unpin)> { let uuid_msg = unique_identifier_msgs::msg::UUID { uuid: self.uuid.as_bytes().to_vec(), }; @@ -213,18 +208,13 @@ where }; if ret != RCL_RET_OK as i32 { - log::debug!( - "action server: could not cancel goal: {}", - Error::from_rcl_error(ret) - ); + log::debug!("action server: could not cancel goal: {}", Error::from_rcl_error(ret)); } } } fn set_goal_state( - &mut self, - uuid: &uuid::Uuid, - new_state: rcl_action_goal_event_t, + &mut self, uuid: &uuid::Uuid, new_state: rcl_action_goal_event_t, ) -> Result<()> { let goal_info = action_msgs::msg::GoalInfo { goal_id: unique_identifier_msgs::msg::UUID { @@ -725,9 +715,7 @@ where } pub fn create_action_server_helper( - node: &mut rcl_node_t, - action_name: &str, - clock_handle: *mut rcl_clock_t, + node: &mut rcl_node_t, action_name: &str, clock_handle: *mut rcl_clock_t, action_ts: *const rosidl_action_type_support_t, ) -> Result { let mut server_handle = unsafe { rcl_action_get_zero_initialized_server() }; @@ -754,12 +742,8 @@ pub fn create_action_server_helper( } pub fn action_server_get_num_waits( - rcl_handle: &rcl_action_server_t, - num_subs: &mut usize, - num_gc: &mut usize, - num_timers: &mut usize, - num_clients: &mut usize, - num_services: &mut usize, + rcl_handle: &rcl_action_server_t, num_subs: &mut usize, num_gc: &mut usize, + num_timers: &mut usize, num_clients: &mut usize, num_services: &mut usize, ) -> Result<()> { unsafe { let result = rcl_action_server_wait_set_get_num_entities( diff --git a/r2r/src/clients.rs b/r2r/src/clients.rs index 7bea2eb..e28aa6a 100644 --- a/r2r/src/clients.rs +++ b/r2r/src/clients.rs @@ -57,8 +57,7 @@ impl ClientUntyped { /// /// Returns a `Future` of Result. pub fn request( - &self, - msg: serde_json::Value, + &self, msg: serde_json::Value, ) -> Result>>> { // upgrade to actual ref. if still alive let client = self.client.upgrade().ok_or(Error::RCL_RET_CLIENT_INVALID)?; @@ -110,8 +109,7 @@ unsafe impl Send for UntypedClient_ {} impl UntypedClient_ { pub fn request( - &mut self, - msg: serde_json::Value, + &mut self, msg: serde_json::Value, ) -> Result>>> { let native_msg = (self.service_type.make_request_msg)(); native_msg.from_json(msg)?; @@ -193,7 +191,8 @@ where .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } // TODO handle failure. @@ -279,7 +278,8 @@ impl Client_ for UntypedClient_ { .join(","); log::error!( "no such req id: {}, we have [{}], ignoring", - request_id.sequence_number, we_have + request_id.sequence_number, + we_have ); } } // TODO handle failure. @@ -319,9 +319,7 @@ impl Client_ for UntypedClient_ { } pub fn create_client_helper( - node: *mut rcl_node_t, - service_name: &str, - service_ts: *const rosidl_service_type_support_t, + node: *mut rcl_node_t, service_name: &str, service_ts: *const rosidl_service_type_support_t, ) -> Result { let mut client_handle = unsafe { rcl_get_zero_initialized_client() }; let service_name_c_string = diff --git a/r2r/src/clocks.rs b/r2r/src/clocks.rs index 993e164..603a6e4 100644 --- a/r2r/src/clocks.rs +++ b/r2r/src/clocks.rs @@ -36,11 +36,7 @@ impl Clock { let rcl_ct = clock_type_to_rcl(&ct); let ret = unsafe { - rcl_clock_init( - rcl_ct, - clock_handle.as_mut_ptr(), - &mut rcutils_get_default_allocator(), - ) + rcl_clock_init(rcl_ct, clock_handle.as_mut_ptr(), &mut rcutils_get_default_allocator()) }; if ret != RCL_RET_OK as i32 { log::error!("could not create {:?} clock: {}", ct, ret); diff --git a/r2r/src/msg_types.rs b/r2r/src/msg_types.rs index cec06d2..49b8a63 100644 --- a/r2r/src/msg_types.rs +++ b/r2r/src/msg_types.rs @@ -13,14 +13,8 @@ pub mod generated_msgs { #![allow(clippy::all)] use super::*; include!(concat!(env!("OUT_DIR"), "/_r2r_generated_msgs.rs")); - include!(concat!( - env!("OUT_DIR"), - "/_r2r_generated_untyped_helper.rs" - )); - include!(concat!( - env!("OUT_DIR"), - "/_r2r_generated_service_helper.rs" - )); + include!(concat!(env!("OUT_DIR"), "/_r2r_generated_untyped_helper.rs")); + include!(concat!(env!("OUT_DIR"), "/_r2r_generated_service_helper.rs")); include!(concat!(env!("OUT_DIR"), "/_r2r_generated_action_helper.rs")); } @@ -70,23 +64,19 @@ pub trait WrappedActionTypeSupport: Debug + Clone { fn get_ts() -> &'static rosidl_action_type_support_t; fn make_goal_request_msg( - goal_id: unique_identifier_msgs::msg::UUID, - goal: Self::Goal, + goal_id: unique_identifier_msgs::msg::UUID, goal: Self::Goal, ) -> <::SendGoal as WrappedServiceTypeSupport>::Request; fn make_goal_response_msg( - accepted: bool, - stamp: builtin_interfaces::msg::Time, + accepted: bool, stamp: builtin_interfaces::msg::Time, ) -> <::SendGoal as WrappedServiceTypeSupport>::Response; fn make_feedback_msg( - goal_id: unique_identifier_msgs::msg::UUID, - feedback: Self::Feedback, + goal_id: unique_identifier_msgs::msg::UUID, feedback: Self::Feedback, ) -> Self::FeedbackMessage; fn make_result_request_msg( goal_id: unique_identifier_msgs::msg::UUID, ) -> <::GetResult as WrappedServiceTypeSupport>::Request; fn make_result_response_msg( - status: i8, - result: Self::Result, + status: i8, result: Self::Result, ) -> <::GetResult as WrappedServiceTypeSupport>::Response; fn destructure_goal_request_msg( msg: <::SendGoal as WrappedServiceTypeSupport>::Request, @@ -366,8 +356,7 @@ where } pub fn from_loaned( - msg: *mut T::CStruct, - deallocator: Box::CStruct)>, + msg: *mut T::CStruct, deallocator: Box::CStruct)>, ) -> Self { WrappedNativeMsg { msg, diff --git a/r2r/src/nodes.rs b/r2r/src/nodes.rs index bc26f4b..330029b 100644 --- a/r2r/src/nodes.rs +++ b/r2r/src/nodes.rs @@ -207,10 +207,8 @@ impl Node { /// its new value. pub fn make_parameter_handler( &mut self, - ) -> Result<( - impl Future + Send, - impl Stream, - )> { + ) -> Result<(impl Future + Send, impl Stream)> + { let mut handlers: Vec + Send>>> = Vec::new(); let (mut event_tx, event_rx) = mpsc::channel::<(String, ParameterValue)>(10); @@ -292,9 +290,7 @@ impl Node { /// /// This function returns a `Stream` of ros messages. pub fn subscribe( - &mut self, - topic: &str, - qos_profile: QosProfile, + &mut self, topic: &str, qos_profile: QosProfile, ) -> Result + Unpin> where T: WrappedTypesupport, @@ -315,9 +311,7 @@ impl Node { /// /// This function returns a `Stream` of ros messages without the rust convenience types. pub fn subscribe_native( - &mut self, - topic: &str, - qos_profile: QosProfile, + &mut self, topic: &str, qos_profile: QosProfile, ) -> Result> + Unpin> where T: WrappedTypesupport, @@ -339,10 +333,7 @@ impl Node { /// This function returns a `Stream` of ros messages as `serde_json::Value`:s. /// Useful when you cannot know the type of the message at compile time. pub fn subscribe_untyped( - &mut self, - topic: &str, - topic_type: &str, - qos_profile: QosProfile, + &mut self, topic: &str, topic_type: &str, qos_profile: QosProfile, ) -> Result> + Unpin> { let msg = WrappedNativeMsgUntyped::new_from(topic_type)?; let subscription_handle = @@ -363,8 +354,7 @@ impl Node { /// This function returns a `Stream` of `ServiceRequest`:s. Call /// `respond` on the Service Request to send the reply. pub fn create_service( - &mut self, - service_name: &str, + &mut self, service_name: &str, ) -> Result> + Unpin> where T: WrappedServiceTypeSupport, @@ -411,9 +401,7 @@ impl Node { /// with `serde_json::Value`s instead of concrete types. Useful /// when you cannot know the type of the message at compile time. pub fn create_client_untyped( - &mut self, - service_name: &str, - service_type: &str, + &mut self, service_name: &str, service_type: &str, ) -> Result { let service_type = UntypedServiceSupport::new_from(service_type)?; let client_handle = @@ -439,8 +427,7 @@ impl Node { /// `spin_once` until available, so spin_once must be called /// repeatedly in order to get the wakeup. pub fn is_available( - &mut self, - client: &dyn IsAvailablePollable, + &mut self, client: &dyn IsAvailablePollable, ) -> Result>> { let (sender, receiver) = oneshot::channel(); client.register_poll_available(sender)?; @@ -480,9 +467,7 @@ impl Node { /// with `serde_json::Value`s instead of concrete types. Useful /// when you cannot know the type of the message at compile time. pub fn create_action_client_untyped( - &mut self, - action_name: &str, - action_type: &str, + &mut self, action_name: &str, action_type: &str, ) -> Result { let action_type_support = UntypedActionSupport::new_from(action_type)?; let client_handle = create_action_client_helper( @@ -513,8 +498,7 @@ impl Node { /// This function returns a stream of `GoalRequest`s, which needs /// to be either accepted or rejected. pub fn create_action_server( - &mut self, - action_name: &str, + &mut self, action_name: &str, ) -> Result> + Unpin> where T: WrappedActionTypeSupport, @@ -522,10 +506,7 @@ impl Node { // for now automatically create a ros clock... let mut clock_handle = MaybeUninit::::uninit(); let ret = unsafe { - rcl_ros_clock_init( - clock_handle.as_mut_ptr(), - &mut rcutils_get_default_allocator(), - ) + rcl_ros_clock_init(clock_handle.as_mut_ptr(), &mut rcutils_get_default_allocator()) }; if ret != RCL_RET_OK as i32 { log::error!("could not create steady clock: {}", ret); @@ -560,9 +541,7 @@ impl Node { /// Create a ROS publisher. pub fn create_publisher( - &mut self, - topic: &str, - qos_profile: QosProfile, + &mut self, topic: &str, qos_profile: QosProfile, ) -> Result> where T: WrappedTypesupport, @@ -577,10 +556,7 @@ impl Node { /// Create a ROS publisher with a type given at runtime. pub fn create_publisher_untyped( - &mut self, - topic: &str, - topic_type: &str, - qos_profile: QosProfile, + &mut self, topic: &str, topic_type: &str, qos_profile: QosProfile, ) -> Result { let dummy = WrappedNativeMsgUntyped::new_from(topic_type)?; let publisher_handle = diff --git a/r2r/src/publishers.rs b/r2r/src/publishers.rs index 98c6dc9..55668c4 100644 --- a/r2r/src/publishers.rs +++ b/r2r/src/publishers.rs @@ -77,9 +77,7 @@ pub fn make_publisher_untyped(handle: Weak, type_: String) -> P } pub fn create_publisher_helper( - node: &mut rcl_node_t, - topic: &str, - typesupport: *const rosidl_message_type_support_t, + node: &mut rcl_node_t, topic: &str, typesupport: *const rosidl_message_type_support_t, qos_profile: QosProfile, ) -> Result { let mut publisher_handle = unsafe { rcl_get_zero_initialized_publisher() }; @@ -117,13 +115,8 @@ impl PublisherUntyped { let native_msg = WrappedNativeMsgUntyped::new_from(&self.type_)?; native_msg.from_json(msg)?; - let result = unsafe { - rcl_publish( - publisher.as_ref(), - native_msg.void_ptr(), - std::ptr::null_mut(), - ) - }; + let result = + unsafe { rcl_publish(publisher.as_ref(), native_msg.void_ptr(), std::ptr::null_mut()) }; if result == RCL_RET_OK as i32 { Ok(()) @@ -149,13 +142,8 @@ where .upgrade() .ok_or(Error::RCL_RET_PUBLISHER_INVALID)?; let native_msg: WrappedNativeMsg = WrappedNativeMsg::::from(msg); - let result = unsafe { - rcl_publish( - publisher.as_ref(), - native_msg.void_ptr(), - std::ptr::null_mut(), - ) - }; + let result = + unsafe { rcl_publish(publisher.as_ref(), native_msg.void_ptr(), std::ptr::null_mut()) }; if result == RCL_RET_OK as i32 { Ok(()) @@ -208,7 +196,9 @@ where } else { static LOG_LOANED_ERROR: Once = Once::new(); LOG_LOANED_ERROR.call_once(|| { - log::error!("Currently used middleware can't loan messages. Local allocator will be used."); + log::error!( + "Currently used middleware can't loan messages. Local allocator will be used." + ); }); Ok(WrappedNativeMsg::::new()) diff --git a/r2r/src/qos.rs b/r2r/src/qos.rs index 84bbb00..abe4c39 100644 --- a/r2r/src/qos.rs +++ b/r2r/src/qos.rs @@ -695,8 +695,7 @@ impl QosProfile { /// let qos = QosProfile::default().avoid_ros_namespace_conventions(true); /// ``` pub const fn avoid_ros_namespace_conventions( - self, - avoid_ros_namespace_conventions: bool, + self, avoid_ros_namespace_conventions: bool, ) -> Self { Self { avoid_ros_namespace_conventions, diff --git a/r2r/src/services.rs b/r2r/src/services.rs index 79529a2..9e07ab9 100644 --- a/r2r/src/services.rs +++ b/r2r/src/services.rs @@ -68,9 +68,7 @@ where } fn send_response( - &mut self, - mut request_id: rmw_request_id_t, - mut msg: Box, + &mut self, mut request_id: rmw_request_id_t, mut msg: Box, ) -> Result<()> { let res = unsafe { rcl_send_response(&self.rcl_handle, &mut request_id, msg.void_ptr_mut()) }; @@ -86,11 +84,7 @@ where let mut request_msg = WrappedNativeMsg::::new(); let ret = unsafe { - rcl_take_request( - &self.rcl_handle, - request_id.as_mut_ptr(), - request_msg.void_ptr_mut(), - ) + rcl_take_request(&self.rcl_handle, request_id.as_mut_ptr(), request_msg.void_ptr_mut()) }; if ret == RCL_RET_OK as i32 { let request_id = unsafe { request_id.assume_init() }; @@ -118,9 +112,7 @@ where } pub fn create_service_helper( - node: &mut rcl_node_t, - service_name: &str, - service_ts: *const rosidl_service_type_support_t, + node: &mut rcl_node_t, service_name: &str, service_ts: *const rosidl_service_type_support_t, ) -> Result { let mut service_handle = unsafe { rcl_get_zero_initialized_service() }; let service_name_c_string = diff --git a/r2r/src/subscribers.rs b/r2r/src/subscribers.rs index 4184ea0..5367ab0 100644 --- a/r2r/src/subscribers.rs +++ b/r2r/src/subscribers.rs @@ -49,12 +49,7 @@ where let mut msg_info = rmw_message_info_t::default(); // we dont care for now let mut msg = WrappedNativeMsg::::new(); let ret = unsafe { - rcl_take( - &self.rcl_handle, - msg.void_ptr_mut(), - &mut msg_info, - std::ptr::null_mut(), - ) + rcl_take(&self.rcl_handle, msg.void_ptr_mut(), &mut msg_info, std::ptr::null_mut()) }; if ret == RCL_RET_OK as i32 { let msg = T::from_native(&msg); @@ -162,12 +157,7 @@ impl Subscriber_ for UntypedSubscriber { let mut msg = WrappedNativeMsgUntyped::new_from(&self.topic_type) .unwrap_or_else(|_| panic!("no typesupport for {}", self.topic_type)); let ret = unsafe { - rcl_take( - &self.rcl_handle, - msg.void_ptr_mut(), - &mut msg_info, - std::ptr::null_mut(), - ) + rcl_take(&self.rcl_handle, msg.void_ptr_mut(), &mut msg_info, std::ptr::null_mut()) }; if ret == RCL_RET_OK as i32 { let json = msg.to_json(); @@ -190,9 +180,7 @@ impl Subscriber_ for UntypedSubscriber { } pub fn create_subscription_helper( - node: &mut rcl_node_t, - topic: &str, - ts: *const rosidl_message_type_support_t, + node: &mut rcl_node_t, topic: &str, ts: *const rosidl_message_type_support_t, qos_profile: QosProfile, ) -> Result { let mut subscription_handle = unsafe { rcl_get_zero_initialized_subscription() }; diff --git a/r2r/src/utils.rs b/r2r/src/utils.rs index ca7c139..72e30f9 100644 --- a/r2r/src/utils.rs +++ b/r2r/src/utils.rs @@ -77,13 +77,7 @@ impl LogSeverity { #[macro_export] macro_rules! __impl_log { ($logger_name:expr, $msg:expr, $file:expr, $line:expr, $severity:expr) => {{ - $crate::log( - &std::fmt::format($msg), - $logger_name, - $file, - $line, - $severity, - ); + $crate::log(&std::fmt::format($msg), $logger_name, $file, $line, $severity); }}; } diff --git a/r2r_actions/build.rs b/r2r_actions/build.rs index 0700f5a..34a437b 100644 --- a/r2r_actions/build.rs +++ b/r2r_actions/build.rs @@ -25,11 +25,7 @@ fn run_bindgen() { if cfg!(feature = "doc-only") { // If "doc-only" feature is present, copy from $crate/bindings/* to OUT_DIR - eprintln!( - "Copy from '{}' to '{}'", - saved_file.display(), - target_file.display() - ); + eprintln!("Copy from '{}' to '{}'", saved_file.display(), target_file.display()); fs::copy(&saved_file, &target_file).unwrap(); } else { // If bindgen was done before, use cached files. diff --git a/r2r_common/src/lib.rs b/r2r_common/src/lib.rs index 2e2284c..40f25d4 100644 --- a/r2r_common/src/lib.rs +++ b/r2r_common/src/lib.rs @@ -409,9 +409,6 @@ std_msgs/msg/String let map = as_map(&parsed); assert_eq!(map.get("std_msgs").unwrap().get("msg").unwrap()[0], "Bool"); - assert_eq!( - map.get("std_msgs").unwrap().get("msg").unwrap()[1], - "String" - ); + assert_eq!(map.get("std_msgs").unwrap().get("msg").unwrap()[1], "String"); } } diff --git a/r2r_msg_gen/build.rs b/r2r_msg_gen/build.rs index be56123..5301bc9 100644 --- a/r2r_msg_gen/build.rs +++ b/r2r_msg_gen/build.rs @@ -50,11 +50,7 @@ fn run_bindgen(msg_list: &[RosMsg]) { if cfg!(feature = "doc-only") { // If "doc-only" feature is present, copy from $crate/bindings/* to OUT_DIR - eprintln!( - "Copy files from '{}' to '{}'", - save_dir.display(), - out_dir.display() - ); + eprintln!("Copy files from '{}' to '{}'", save_dir.display(), out_dir.display()); for filename in GENERATED_FILES { let src = save_dir.join(filename); @@ -549,14 +545,8 @@ fn run_dynlink(msg_list: &[RosMsg]) { let msg_map = r2r_common::as_map(msg_list); for module in msg_map.keys() { - println!( - "cargo:rustc-link-lib=dylib={}__rosidl_typesupport_c", - module - ); - println!( - "cargo:rustc-link-lib=dylib={}__rosidl_typesupport_introspection_c", - module - ); + println!("cargo:rustc-link-lib=dylib={}__rosidl_typesupport_c", module); + println!("cargo:rustc-link-lib=dylib={}__rosidl_typesupport_introspection_c", module); println!("cargo:rustc-link-lib=dylib={}__rosidl_generator_c", module); } } diff --git a/r2r_msg_gen/src/lib.rs b/r2r_msg_gen/src/lib.rs index 392d56c..e019d1f 100644 --- a/r2r_msg_gen/src/lib.rs +++ b/r2r_msg_gen/src/lib.rs @@ -149,20 +149,12 @@ unsafe fn introspection<'a>( msgname = name ); let memberslice = slice::from_raw_parts((*members).members_, (*members).member_count_ as usize); - ( - module.to_owned(), - prefix.to_owned(), - name.to_owned(), - c_struct, - memberslice, - ) + (module.to_owned(), prefix.to_owned(), name.to_owned(), c_struct, memberslice) } #[cfg(not(feature = "doc-only"))] pub fn generate_rust_service( - module_: &str, - prefix_: &str, - name_: &str, + module_: &str, prefix_: &str, name_: &str, ) -> proc_macro2::TokenStream { let ident = format_ident!( "rosidl_typesupport_c__\ diff --git a/r2r_rcl/build.rs b/r2r_rcl/build.rs index ac7cbb6..f5ea061 100644 --- a/r2r_rcl/build.rs +++ b/r2r_rcl/build.rs @@ -48,11 +48,7 @@ fn run_bindgen() { }; fs::copy(src_file, &target_file).unwrap_or_else(|_| { - panic!( - "Unable to copy from '{}' to '{}'", - src_file.display(), - target_file.display() - ) + panic!("Unable to copy from '{}' to '{}'", src_file.display(), target_file.display()) }); } diff --git a/rustfmt.toml b/rustfmt.toml index 2e97035..84c3617 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,3 +2,5 @@ hard_tabs = false tab_spaces = 4 reorder_imports = true newline_style = "Unix" +fn_call_width = 80 +fn_params_layout = "Compressed"