Skip to content

Commit 0874d8d

Browse files
committed
Fix formatting
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 1ec9f10 commit 0874d8d

File tree

10 files changed

+58
-72
lines changed

10 files changed

+58
-72
lines changed

rclrs/src/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
vec::Vec,
77
};
88

9-
use crate::{rcl_bindings::*, RclrsError, ToResult, Executor};
9+
use crate::{rcl_bindings::*, Executor, RclrsError, ToResult};
1010

1111
/// This is locked whenever initializing or dropping any middleware entity
1212
/// because we have found issues in RCL and some RMW implementations that
@@ -74,8 +74,7 @@ impl Default for Context {
7474
fn default() -> Self {
7575
// SAFETY: It should always be valid to instantiate a context with no
7676
// arguments, no parameters, no options, etc.
77-
Self::new([], InitOptions::default())
78-
.expect("Failed to instantiate a default context")
77+
Self::new([], InitOptions::default()).expect("Failed to instantiate a default context")
7978
}
8079
}
8180

rclrs/src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,13 @@ impl RclrsErrorFilter for Result<(), RclrsError> {
364364
match self {
365365
Ok(()) => Ok(()),
366366
Err(err) => {
367-
if matches!(err, RclrsError::RclError { code: RclReturnCode::Timeout, .. }) {
367+
if matches!(
368+
err,
369+
RclrsError::RclError {
370+
code: RclReturnCode::Timeout,
371+
..
372+
}
373+
) {
368374
return Ok(());
369375
}
370376

rclrs/src/executor.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
rcl_bindings::rcl_context_is_valid,
3-
Node, RclrsError, WaitSet, ContextHandle, NodeOptions, WeakNode,
2+
rcl_bindings::rcl_context_is_valid, ContextHandle, Node, NodeOptions, RclrsError, WaitSet,
3+
WeakNode,
44
};
55
use std::{
66
sync::{Arc, Mutex},
@@ -15,10 +15,7 @@ pub struct Executor {
1515

1616
impl Executor {
1717
/// Create a [`Node`] that will run on this Executor.
18-
pub fn create_node(
19-
&self,
20-
options: impl Into<NodeOptions>,
21-
) -> Result<Node, RclrsError> {
18+
pub fn create_node(&self, options: impl Into<NodeOptions>) -> Result<Node, RclrsError> {
2219
let options: NodeOptions = options.into();
2320
let node = options.build(&self.context)?;
2421
self.nodes_mtx.lock().unwrap().push(node.downgrade());

rclrs/src/node.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod node_options;
21
mod graph;
2+
mod node_options;
33
use std::{
44
cmp::PartialEq,
55
ffi::CStr,
@@ -13,10 +13,10 @@ use rosidl_runtime_rs::Message;
1313

1414
pub use self::{graph::*, node_options::*};
1515
use crate::{
16-
rcl_bindings::*, Client, ClientBase, Clock, ContextHandle, GuardCondition,
17-
ParameterBuilder, ParameterInterface, ParameterVariant, Parameters, Publisher, QoSProfile,
18-
RclrsError, Service, ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback,
19-
TimeSource, ENTITY_LIFECYCLE_MUTEX,
16+
rcl_bindings::*, Client, ClientBase, Clock, ContextHandle, GuardCondition, ParameterBuilder,
17+
ParameterInterface, ParameterVariant, Parameters, Publisher, QoSProfile, RclrsError, Service,
18+
ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback, TimeSource,
19+
ENTITY_LIFECYCLE_MUTEX,
2020
};
2121

2222
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
@@ -213,7 +213,8 @@ impl Node {
213213
T: rosidl_runtime_rs::Service,
214214
{
215215
let client = Arc::new(Client::<T>::new(Arc::clone(&self.handle), topic)?);
216-
{ self.primitives.clients_mtx.lock().unwrap() }.push(Arc::downgrade(&client) as Weak<dyn ClientBase>);
216+
{ self.primitives.clients_mtx.lock().unwrap() }
217+
.push(Arc::downgrade(&client) as Weak<dyn ClientBase>);
217218
Ok(client)
218219
}
219220

rclrs/src/node/graph.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ mod tests {
482482
.map(|value: usize| if value != 99 { 99 } else { 98 })
483483
.unwrap_or(99);
484484

485-
let executor =
486-
Context::new([], InitOptions::new().with_domain_id(Some(domain_id)))
485+
let executor = Context::new([], InitOptions::new().with_domain_id(Some(domain_id)))
487486
.unwrap()
488487
.create_basic_executor();
489488
let node_name = "test_publisher_names_and_types";

rclrs/src/node/node_options.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::{
44
};
55

66
use crate::{
7-
rcl_bindings::*,
8-
ClockType, Node, NodeHandle, ParameterInterface, NodePrimitives, ContextHandle,
9-
QoSProfile, RclrsError, TimeSource, ToResult, ENTITY_LIFECYCLE_MUTEX, QOS_PROFILE_CLOCK,
7+
rcl_bindings::*, ClockType, ContextHandle, Node, NodeHandle, NodePrimitives,
8+
ParameterInterface, QoSProfile, RclrsError, TimeSource, ToResult, ENTITY_LIFECYCLE_MUTEX,
9+
QOS_PROFILE_CLOCK,
1010
};
1111

1212
/// A set of options for creating a [`Node`][1].
@@ -257,10 +257,7 @@ impl NodeOptions {
257257
///
258258
/// Only used internally. Downstream users should call
259259
/// [`Executor::create_node`].
260-
pub(crate) fn build(
261-
self,
262-
context: &Arc<ContextHandle>,
263-
) -> Result<Node, RclrsError> {
260+
pub(crate) fn build(self, context: &Arc<ContextHandle>) -> Result<Node, RclrsError> {
264261
let node_name =
265262
CString::new(self.name.as_str()).map_err(|err| RclrsError::StringContainsNul {
266263
err,

rclrs/src/parameter/service.rs

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ mod tests {
312312
},
313313
srv::rmw::*,
314314
},
315-
Context, MandatoryParameter, Node, ParameterRange, ParameterValue, RclrsError,
316-
ReadOnlyParameter, NodeOptions, Executor, SpinOptions, RclrsErrorFilter,
315+
Context, Executor, MandatoryParameter, Node, NodeOptions, ParameterRange, ParameterValue,
316+
RclrsError, RclrsErrorFilter, ReadOnlyParameter, SpinOptions,
317317
};
318318
use rosidl_runtime_rs::{seq, Sequence};
319319
use std::{
@@ -346,11 +346,9 @@ mod tests {
346346

347347
fn construct_test_nodes(ns: &str) -> (Executor, TestNode, Node) {
348348
let executor = Context::default().create_basic_executor();
349-
let node = executor.create_node(
350-
NodeOptions::new("node")
351-
.namespace(ns)
352-
)
353-
.unwrap();
349+
let node = executor
350+
.create_node(NodeOptions::new("node").namespace(ns))
351+
.unwrap();
354352
let range = ParameterRange {
355353
lower: Some(0),
356354
upper: Some(100),
@@ -380,11 +378,9 @@ mod tests {
380378
.mandatory()
381379
.unwrap();
382380

383-
let client = executor.create_node(
384-
NodeOptions::new("client")
385-
.namespace(ns)
386-
)
387-
.unwrap();
381+
let client = executor
382+
.create_node(NodeOptions::new("client").namespace(ns))
383+
.unwrap();
388384

389385
(
390386
executor,
@@ -447,12 +443,10 @@ mod tests {
447443
let inner_done = done.clone();
448444
let rclrs_spin = tokio::task::spawn(async move {
449445
try_until_timeout(move || {
450-
executor.spin(
451-
SpinOptions::spin_once()
452-
.timeout(Duration::ZERO)
453-
)
454-
.timeout_ok()
455-
.unwrap();
446+
executor
447+
.spin(SpinOptions::spin_once().timeout(Duration::ZERO))
448+
.timeout_ok()
449+
.unwrap();
456450

457451
*inner_done.read().unwrap()
458452
})
@@ -594,12 +588,10 @@ mod tests {
594588
let rclrs_spin = tokio::task::spawn(async move {
595589
try_until_timeout(move || {
596590
println!(" -- spin");
597-
executor.spin(
598-
SpinOptions::spin_once()
599-
.timeout(Duration::ZERO)
600-
)
601-
.timeout_ok()
602-
.unwrap();
591+
executor
592+
.spin(SpinOptions::spin_once().timeout(Duration::ZERO))
593+
.timeout_ok()
594+
.unwrap();
603595

604596
*inner_done.read().unwrap()
605597
})
@@ -657,8 +649,8 @@ mod tests {
657649
println!("checking client");
658650
*client_finished.read().unwrap()
659651
})
660-
.await
661-
.unwrap();
652+
.await
653+
.unwrap();
662654

663655
// Set a mix of existing, non existing, dynamic and out of range parameters
664656
let bool_parameter = RmwParameter {
@@ -807,8 +799,8 @@ mod tests {
807799
println!("checking client finished");
808800
*client_finished.read().unwrap()
809801
})
810-
.await
811-
.unwrap();
802+
.await
803+
.unwrap();
812804
*done.write().unwrap() = true;
813805
});
814806

@@ -838,12 +830,10 @@ mod tests {
838830
let inner_done = done.clone();
839831
let rclrs_spin = tokio::task::spawn(async move {
840832
try_until_timeout(move || {
841-
executor.spin(
842-
SpinOptions::spin_once()
843-
.timeout(Duration::ZERO)
844-
)
845-
.timeout_ok()
846-
.unwrap();
833+
executor
834+
.spin(SpinOptions::spin_once().timeout(Duration::ZERO))
835+
.timeout_ok()
836+
.unwrap();
847837

848838
*inner_done.read().unwrap()
849839
})

rclrs/src/parameter/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl ParameterValue {
537537
#[cfg(test)]
538538
mod tests {
539539
use super::*;
540-
use crate::{Context, RclrsError, ToResult, InitOptions};
540+
use crate::{Context, InitOptions, RclrsError, ToResult};
541541

542542
// TODO(luca) tests for all from / to ParameterVariant functions
543543

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Context, Node, RclrsError, NodeOptions};
1+
use crate::{Context, Node, NodeOptions, RclrsError};
22

33
pub(crate) struct TestGraph {
44
pub node1: Node,
@@ -8,13 +8,7 @@ pub(crate) struct TestGraph {
88
pub(crate) fn construct_test_graph(namespace: &str) -> Result<TestGraph, RclrsError> {
99
let executor = Context::default().create_basic_executor();
1010
Ok(TestGraph {
11-
node1: executor.create_node(
12-
NodeOptions::new("graph_test_node_1")
13-
.namespace(namespace)
14-
)?,
15-
node2: executor.create_node(
16-
NodeOptions::new("graph_test_node_2")
17-
.namespace(namespace)
18-
)?,
11+
node1: executor.create_node(NodeOptions::new("graph_test_node_1").namespace(namespace))?,
12+
node2: executor.create_node(NodeOptions::new("graph_test_node_2").namespace(namespace))?,
1913
})
2014
}

rclrs/src/time_source.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
clock::{Clock, ClockSource, ClockType},
33
vendor::rosgraph_msgs::msg::Clock as ClockMsg,
4-
Node, QoSProfile, ReadOnlyParameter, Subscription, QOS_PROFILE_CLOCK, WeakNode,
4+
Node, QoSProfile, ReadOnlyParameter, Subscription, WeakNode, QOS_PROFILE_CLOCK,
55
};
66
use std::sync::{Arc, Mutex, RwLock};
77

@@ -149,7 +149,10 @@ mod tests {
149149

150150
#[test]
151151
fn time_source_default_clock() {
152-
let node = Context::default().create_basic_executor().create_node("test_node").unwrap();
152+
let node = Context::default()
153+
.create_basic_executor()
154+
.create_node("test_node")
155+
.unwrap();
153156
// Default clock should be above 0 (use_sim_time is default false)
154157
assert!(node.get_clock().now().nsec > 0);
155158
}
@@ -162,7 +165,7 @@ mod tests {
162165
String::from("-p"),
163166
String::from("use_sim_time:=true"),
164167
],
165-
InitOptions::default()
168+
InitOptions::default(),
166169
)
167170
.unwrap()
168171
.create_basic_executor();

0 commit comments

Comments
 (0)