diff --git a/rclrs/src/context.rs b/rclrs/src/context.rs index 5d50d1d8d..17894ca46 100644 --- a/rclrs/src/context.rs +++ b/rclrs/src/context.rs @@ -6,7 +6,7 @@ use std::{ vec::Vec, }; -use crate::{rcl_bindings::*, RclrsError, ToResult, Executor}; +use crate::{rcl_bindings::*, Executor, RclrsError, ToResult}; /// This is locked whenever initializing or dropping any middleware entity /// because we have found issues in RCL and some RMW implementations that @@ -74,8 +74,7 @@ impl Default for Context { fn default() -> Self { // SAFETY: It should always be valid to instantiate a context with no // arguments, no parameters, no options, etc. - Self::new([], InitOptions::default()) - .expect("Failed to instantiate a default context") + Self::new([], InitOptions::default()).expect("Failed to instantiate a default context") } } diff --git a/rclrs/src/error.rs b/rclrs/src/error.rs index 515a5b95c..961e7d5e6 100644 --- a/rclrs/src/error.rs +++ b/rclrs/src/error.rs @@ -364,7 +364,13 @@ impl RclrsErrorFilter for Result<(), RclrsError> { match self { Ok(()) => Ok(()), Err(err) => { - if matches!(err, RclrsError::RclError { code: RclReturnCode::Timeout, .. }) { + if matches!( + err, + RclrsError::RclError { + code: RclReturnCode::Timeout, + .. + } + ) { return Ok(()); } diff --git a/rclrs/src/executor.rs b/rclrs/src/executor.rs index 63951afef..3202bd34f 100644 --- a/rclrs/src/executor.rs +++ b/rclrs/src/executor.rs @@ -1,6 +1,6 @@ use crate::{ - rcl_bindings::rcl_context_is_valid, - Node, RclrsError, WaitSet, ContextHandle, NodeOptions, WeakNode, + rcl_bindings::rcl_context_is_valid, ContextHandle, Node, NodeOptions, RclrsError, WaitSet, + WeakNode, }; use std::{ sync::{Arc, Mutex}, @@ -15,10 +15,7 @@ pub struct Executor { impl Executor { /// Create a [`Node`] that will run on this Executor. - pub fn create_node( - &self, - options: impl Into, - ) -> Result { + pub fn create_node(&self, options: impl Into) -> Result { let options: NodeOptions = options.into(); let node = options.build(&self.context)?; self.nodes_mtx.lock().unwrap().push(node.downgrade()); diff --git a/rclrs/src/node.rs b/rclrs/src/node.rs index f23a17d6d..42cb3a226 100644 --- a/rclrs/src/node.rs +++ b/rclrs/src/node.rs @@ -1,5 +1,5 @@ -mod node_options; mod graph; +mod node_options; use std::{ cmp::PartialEq, ffi::CStr, @@ -13,10 +13,10 @@ use rosidl_runtime_rs::Message; pub use self::{graph::*, node_options::*}; use crate::{ - rcl_bindings::*, Client, ClientBase, Clock, ContextHandle, GuardCondition, - ParameterBuilder, ParameterInterface, ParameterVariant, Parameters, Publisher, QoSProfile, - RclrsError, Service, ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback, - TimeSource, ENTITY_LIFECYCLE_MUTEX, + rcl_bindings::*, Client, ClientBase, Clock, ContextHandle, GuardCondition, ParameterBuilder, + ParameterInterface, ParameterVariant, Parameters, Publisher, QoSProfile, RclrsError, Service, + ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback, TimeSource, + ENTITY_LIFECYCLE_MUTEX, }; // SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread @@ -213,7 +213,8 @@ impl Node { T: rosidl_runtime_rs::Service, { let client = Arc::new(Client::::new(Arc::clone(&self.handle), topic)?); - { self.primitives.clients_mtx.lock().unwrap() }.push(Arc::downgrade(&client) as Weak); + { self.primitives.clients_mtx.lock().unwrap() } + .push(Arc::downgrade(&client) as Weak); Ok(client) } diff --git a/rclrs/src/node/graph.rs b/rclrs/src/node/graph.rs index 106fac72c..385612155 100644 --- a/rclrs/src/node/graph.rs +++ b/rclrs/src/node/graph.rs @@ -482,8 +482,7 @@ mod tests { .map(|value: usize| if value != 99 { 99 } else { 98 }) .unwrap_or(99); - let executor = - Context::new([], InitOptions::new().with_domain_id(Some(domain_id))) + let executor = Context::new([], InitOptions::new().with_domain_id(Some(domain_id))) .unwrap() .create_basic_executor(); let node_name = "test_publisher_names_and_types"; diff --git a/rclrs/src/node/node_options.rs b/rclrs/src/node/node_options.rs index e4172719d..ae88182cb 100644 --- a/rclrs/src/node/node_options.rs +++ b/rclrs/src/node/node_options.rs @@ -4,9 +4,9 @@ use std::{ }; use crate::{ - rcl_bindings::*, - ClockType, Node, NodeHandle, ParameterInterface, NodePrimitives, ContextHandle, - QoSProfile, RclrsError, TimeSource, ToResult, ENTITY_LIFECYCLE_MUTEX, QOS_PROFILE_CLOCK, + rcl_bindings::*, ClockType, ContextHandle, Node, NodeHandle, NodePrimitives, + ParameterInterface, QoSProfile, RclrsError, TimeSource, ToResult, ENTITY_LIFECYCLE_MUTEX, + QOS_PROFILE_CLOCK, }; /// A set of options for creating a [`Node`][1]. @@ -257,10 +257,7 @@ impl NodeOptions { /// /// Only used internally. Downstream users should call /// [`Executor::create_node`]. - pub(crate) fn build( - self, - context: &Arc, - ) -> Result { + pub(crate) fn build(self, context: &Arc) -> Result { let node_name = CString::new(self.name.as_str()).map_err(|err| RclrsError::StringContainsNul { err, diff --git a/rclrs/src/parameter/service.rs b/rclrs/src/parameter/service.rs index 11df07f28..6a30a6833 100644 --- a/rclrs/src/parameter/service.rs +++ b/rclrs/src/parameter/service.rs @@ -312,8 +312,8 @@ mod tests { }, srv::rmw::*, }, - Context, MandatoryParameter, Node, ParameterRange, ParameterValue, RclrsError, - ReadOnlyParameter, NodeOptions, Executor, SpinOptions, RclrsErrorFilter, + Context, Executor, MandatoryParameter, Node, NodeOptions, ParameterRange, ParameterValue, + RclrsError, RclrsErrorFilter, ReadOnlyParameter, SpinOptions, }; use rosidl_runtime_rs::{seq, Sequence}; use std::{ @@ -346,11 +346,9 @@ mod tests { fn construct_test_nodes(ns: &str) -> (Executor, TestNode, Node) { let executor = Context::default().create_basic_executor(); - let node = executor.create_node( - NodeOptions::new("node") - .namespace(ns) - ) - .unwrap(); + let node = executor + .create_node(NodeOptions::new("node").namespace(ns)) + .unwrap(); let range = ParameterRange { lower: Some(0), upper: Some(100), @@ -380,11 +378,9 @@ mod tests { .mandatory() .unwrap(); - let client = executor.create_node( - NodeOptions::new("client") - .namespace(ns) - ) - .unwrap(); + let client = executor + .create_node(NodeOptions::new("client").namespace(ns)) + .unwrap(); ( executor, @@ -447,12 +443,10 @@ mod tests { let inner_done = done.clone(); let rclrs_spin = tokio::task::spawn(async move { try_until_timeout(move || { - executor.spin( - SpinOptions::spin_once() - .timeout(Duration::ZERO) - ) - .timeout_ok() - .unwrap(); + executor + .spin(SpinOptions::spin_once().timeout(Duration::ZERO)) + .timeout_ok() + .unwrap(); *inner_done.read().unwrap() }) @@ -594,12 +588,10 @@ mod tests { let rclrs_spin = tokio::task::spawn(async move { try_until_timeout(move || { println!(" -- spin"); - executor.spin( - SpinOptions::spin_once() - .timeout(Duration::ZERO) - ) - .timeout_ok() - .unwrap(); + executor + .spin(SpinOptions::spin_once().timeout(Duration::ZERO)) + .timeout_ok() + .unwrap(); *inner_done.read().unwrap() }) @@ -657,8 +649,8 @@ mod tests { println!("checking client"); *client_finished.read().unwrap() }) - .await - .unwrap(); + .await + .unwrap(); // Set a mix of existing, non existing, dynamic and out of range parameters let bool_parameter = RmwParameter { @@ -807,8 +799,8 @@ mod tests { println!("checking client finished"); *client_finished.read().unwrap() }) - .await - .unwrap(); + .await + .unwrap(); *done.write().unwrap() = true; }); @@ -838,12 +830,10 @@ mod tests { let inner_done = done.clone(); let rclrs_spin = tokio::task::spawn(async move { try_until_timeout(move || { - executor.spin( - SpinOptions::spin_once() - .timeout(Duration::ZERO) - ) - .timeout_ok() - .unwrap(); + executor + .spin(SpinOptions::spin_once().timeout(Duration::ZERO)) + .timeout_ok() + .unwrap(); *inner_done.read().unwrap() }) diff --git a/rclrs/src/parameter/value.rs b/rclrs/src/parameter/value.rs index 3a20ae24b..ff0c86c46 100644 --- a/rclrs/src/parameter/value.rs +++ b/rclrs/src/parameter/value.rs @@ -537,7 +537,7 @@ impl ParameterValue { #[cfg(test)] mod tests { use super::*; - use crate::{Context, RclrsError, ToResult, InitOptions}; + use crate::{Context, InitOptions, RclrsError, ToResult}; // TODO(luca) tests for all from / to ParameterVariant functions diff --git a/rclrs/src/test_helpers/graph_helpers.rs b/rclrs/src/test_helpers/graph_helpers.rs index ce3e82f67..8596cebd1 100644 --- a/rclrs/src/test_helpers/graph_helpers.rs +++ b/rclrs/src/test_helpers/graph_helpers.rs @@ -1,4 +1,4 @@ -use crate::{Context, Node, RclrsError, NodeOptions}; +use crate::{Context, Node, NodeOptions, RclrsError}; pub(crate) struct TestGraph { pub node1: Node, @@ -8,13 +8,7 @@ pub(crate) struct TestGraph { pub(crate) fn construct_test_graph(namespace: &str) -> Result { let executor = Context::default().create_basic_executor(); Ok(TestGraph { - node1: executor.create_node( - NodeOptions::new("graph_test_node_1") - .namespace(namespace) - )?, - node2: executor.create_node( - NodeOptions::new("graph_test_node_2") - .namespace(namespace) - )?, + node1: executor.create_node(NodeOptions::new("graph_test_node_1").namespace(namespace))?, + node2: executor.create_node(NodeOptions::new("graph_test_node_2").namespace(namespace))?, }) } diff --git a/rclrs/src/time_source.rs b/rclrs/src/time_source.rs index a5dcad50f..7cb4010c7 100644 --- a/rclrs/src/time_source.rs +++ b/rclrs/src/time_source.rs @@ -1,7 +1,7 @@ use crate::{ clock::{Clock, ClockSource, ClockType}, vendor::rosgraph_msgs::msg::Clock as ClockMsg, - Node, QoSProfile, ReadOnlyParameter, Subscription, QOS_PROFILE_CLOCK, WeakNode, + Node, QoSProfile, ReadOnlyParameter, Subscription, WeakNode, QOS_PROFILE_CLOCK, }; use std::sync::{Arc, Mutex, RwLock}; @@ -149,7 +149,10 @@ mod tests { #[test] fn time_source_default_clock() { - let node = Context::default().create_basic_executor().create_node("test_node").unwrap(); + let node = Context::default() + .create_basic_executor() + .create_node("test_node") + .unwrap(); // Default clock should be above 0 (use_sim_time is default false) assert!(node.get_clock().now().nsec > 0); } @@ -162,7 +165,7 @@ mod tests { String::from("-p"), String::from("use_sim_time:=true"), ], - InitOptions::default() + InitOptions::default(), ) .unwrap() .create_basic_executor();