Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
  • Loading branch information
mxgrey committed Nov 20, 2024
1 parent 1ec9f10 commit 0874d8d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 72 deletions.
5 changes: 2 additions & 3 deletions rclrs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}

Expand Down
8 changes: 7 additions & 1 deletion rclrs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}

Expand Down
9 changes: 3 additions & 6 deletions rclrs/src/executor.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<NodeOptions>,
) -> Result<Node, RclrsError> {
pub fn create_node(&self, options: impl Into<NodeOptions>) -> Result<Node, RclrsError> {
let options: NodeOptions = options.into();
let node = options.build(&self.context)?;
self.nodes_mtx.lock().unwrap().push(node.downgrade());
Expand Down
13 changes: 7 additions & 6 deletions rclrs/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod node_options;
mod graph;
mod node_options;
use std::{
cmp::PartialEq,
ffi::CStr,
Expand All @@ -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
Expand Down Expand Up @@ -213,7 +213,8 @@ impl Node {
T: rosidl_runtime_rs::Service,
{
let client = Arc::new(Client::<T>::new(Arc::clone(&self.handle), topic)?);
{ self.primitives.clients_mtx.lock().unwrap() }.push(Arc::downgrade(&client) as Weak<dyn ClientBase>);
{ self.primitives.clients_mtx.lock().unwrap() }
.push(Arc::downgrade(&client) as Weak<dyn ClientBase>);
Ok(client)
}

Expand Down
3 changes: 1 addition & 2 deletions rclrs/src/node/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
11 changes: 4 additions & 7 deletions rclrs/src/node/node_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -257,10 +257,7 @@ impl NodeOptions {
///
/// Only used internally. Downstream users should call
/// [`Executor::create_node`].
pub(crate) fn build(
self,
context: &Arc<ContextHandle>,
) -> Result<Node, RclrsError> {
pub(crate) fn build(self, context: &Arc<ContextHandle>) -> Result<Node, RclrsError> {
let node_name =
CString::new(self.name.as_str()).map_err(|err| RclrsError::StringContainsNul {
err,
Expand Down
58 changes: 24 additions & 34 deletions rclrs/src/parameter/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -807,8 +799,8 @@ mod tests {
println!("checking client finished");
*client_finished.read().unwrap()
})
.await
.unwrap();
.await
.unwrap();
*done.write().unwrap() = true;
});

Expand Down Expand Up @@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion rclrs/src/parameter/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 3 additions & 9 deletions rclrs/src/test_helpers/graph_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Context, Node, RclrsError, NodeOptions};
use crate::{Context, Node, NodeOptions, RclrsError};

pub(crate) struct TestGraph {
pub node1: Node,
Expand All @@ -8,13 +8,7 @@ pub(crate) struct TestGraph {
pub(crate) fn construct_test_graph(namespace: &str) -> Result<TestGraph, RclrsError> {
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))?,
})
}
9 changes: 6 additions & 3 deletions rclrs/src/time_source.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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);
}
Expand All @@ -162,7 +165,7 @@ mod tests {
String::from("-p"),
String::from("use_sim_time:=true"),
],
InitOptions::default()
InitOptions::default(),
)
.unwrap()
.create_basic_executor();
Expand Down

0 comments on commit 0874d8d

Please sign in to comment.