Skip to content

Commit 1f4a8b9

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

24 files changed

+219
-227
lines changed

rclrs/src/client.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use std::{
88
use rosidl_runtime_rs::Message;
99

1010
use crate::{
11-
error::ToResult, rcl_bindings::*, IntoPrimitiveOptions, MessageCow, Node, Promise, QoSProfile,
12-
RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclReturnCode, RclrsError, ServiceInfo,
13-
Waitable, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX, log_fatal,
11+
error::ToResult, log_fatal, rcl_bindings::*, IntoPrimitiveOptions, MessageCow, Node, Promise,
12+
QoSProfile, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclReturnCode, RclrsError,
13+
ServiceInfo, Waitable, WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX,
1414
};
1515

1616
mod client_async_callback;
@@ -284,9 +284,9 @@ where
284284
/// `until_promise_resolved` in [`SpinOptions`][crate::SpinOptions].
285285
pub fn notify_on_service_ready(self: &Arc<Self>) -> Promise<()> {
286286
let client = Arc::clone(self);
287-
self.handle.node.notify_on_graph_change(
288-
move || client.service_is_ready().is_ok_and(|r| r),
289-
)
287+
self.handle
288+
.node
289+
.notify_on_graph_change(move || client.service_is_ready().is_ok_and(|r| r))
290290
}
291291

292292
/// Get the name of the service that this client intends to call.
@@ -598,4 +598,3 @@ mod tests {
598598
Ok(())
599599
}
600600
}
601-

rclrs/src/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use std::{
66
vec::Vec,
77
};
88

9-
use crate::{
10-
rcl_bindings::*, Executor, ExecutorRuntime, LoggingLifecycle, RclrsError,
11-
ToResult,
12-
};
9+
use crate::{rcl_bindings::*, Executor, ExecutorRuntime, LoggingLifecycle, RclrsError, ToResult};
1310

1411
/// This is locked whenever initializing or dropping any middleware entity
1512
/// because we have found issues in RCL and some RMW implementations that

rclrs/src/error.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,10 @@ impl Display for RclrsError {
113113
)
114114
}
115115
RclrsError::ParameterDeclarationError(err) => {
116-
write!(
117-
f,
118-
"An error occurred while declaring a parameter: {err}",
119-
)
116+
write!(f, "An error occurred while declaring a parameter: {err}",)
120117
}
121118
RclrsError::PoisonedMutex => {
122-
write!(
123-
f,
124-
"A mutex used internally has been poisoned"
125-
)
119+
write!(f, "A mutex used internally has been poisoned")
126120
}
127121
}
128122
}

rclrs/src/executor.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
mod basic_executor;
22
pub use self::basic_executor::*;
33

4-
use crate::{WeakActivityListener, Context, ContextHandle, GuardCondition, IntoNodeOptions, Node, RclrsError, Waitable};
4+
use crate::{
5+
Context, ContextHandle, GuardCondition, IntoNodeOptions, Node, RclrsError, Waitable,
6+
WeakActivityListener,
7+
};
58
pub use futures::channel::oneshot::Receiver as Promise;
69
use futures::{
710
channel::oneshot,
@@ -92,7 +95,9 @@ impl Executor {
9295
{
9396
let executor_channel = runtime.channel();
9497
let async_worker_commands = ExecutorCommands::impl_create_worker_commands(
95-
&Context { handle: Arc::clone(&context) },
98+
&Context {
99+
handle: Arc::clone(&context),
100+
},
96101
&*executor_channel,
97102
Box::new(()),
98103
);
@@ -168,16 +173,18 @@ impl ExecutorCommands {
168173
F::Output: Send,
169174
{
170175
let (mut sender, receiver) = oneshot::channel();
171-
self.async_worker_commands.channel.add_async_task(Box::pin(async move {
172-
let cancellation = sender.cancellation();
173-
let output = match select(cancellation, std::pin::pin!(f)).await {
174-
// The task was cancelled
175-
Either::Left(_) => return,
176-
// The task completed
177-
Either::Right((output, _)) => output,
178-
};
179-
sender.send(output).ok();
180-
}));
176+
self.async_worker_commands
177+
.channel
178+
.add_async_task(Box::pin(async move {
179+
let cancellation = sender.cancellation();
180+
let output = match select(cancellation, std::pin::pin!(f)).await {
181+
// The task was cancelled
182+
Either::Left(_) => return,
183+
// The task completed
184+
Either::Right((output, _)) => output,
185+
};
186+
sender.send(output).ok();
187+
}));
181188

182189
receiver
183190
}
@@ -203,9 +210,11 @@ impl ExecutorCommands {
203210
F::Output: Send,
204211
{
205212
let (sender, receiver) = oneshot::channel();
206-
self.async_worker_commands.channel.add_async_task(Box::pin(async move {
207-
sender.send(f.await).ok();
208-
}));
213+
self.async_worker_commands
214+
.channel
215+
.add_async_task(Box::pin(async move {
216+
sender.send(f.await).ok();
217+
}));
209218
receiver
210219
}
211220

@@ -244,7 +253,10 @@ impl ExecutorCommands {
244253
&self.async_worker_commands
245254
}
246255

247-
pub(crate) fn create_worker_commands(&self, payload: Box<dyn Any + Send>) -> Arc<WorkerCommands> {
256+
pub(crate) fn create_worker_commands(
257+
&self,
258+
payload: Box<dyn Any + Send>,
259+
) -> Arc<WorkerCommands> {
248260
Self::impl_create_worker_commands(&self.context, &*self.executor_channel, payload)
249261
}
250262

@@ -344,10 +356,7 @@ pub struct ExecutorWorkerOptions {
344356
pub trait ExecutorChannel: Send + Sync {
345357
/// Create a new channel specific to a worker whose payload must be
346358
/// initialized with the given function.
347-
fn create_worker(
348-
&self,
349-
options: ExecutorWorkerOptions,
350-
) -> Arc<dyn WorkerChannel>;
359+
fn create_worker(&self, options: ExecutorWorkerOptions) -> Arc<dyn WorkerChannel>;
351360

352361
/// Wake all the wait sets that are being managed by this executor. This is
353362
/// used to make sure they respond to [`ExecutorCommands::halt_spinning`].
@@ -477,4 +486,3 @@ impl CreateBasicExecutor for Context {
477486
self.create_executor(runtime)
478487
}
479488
}
480-

rclrs/src/executor/basic_executor.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use futures::{
2-
channel::{mpsc::{UnboundedSender, UnboundedReceiver, unbounded}, oneshot},
3-
future::{BoxFuture, select, select_all, Either},
4-
task::{waker_ref, ArcWake},
2+
channel::{
3+
mpsc::{unbounded, UnboundedReceiver, UnboundedSender},
4+
oneshot,
5+
},
6+
future::{select, select_all, BoxFuture, Either},
57
stream::StreamFuture,
8+
task::{waker_ref, ArcWake},
69
StreamExt,
710
};
811
use std::{
@@ -16,9 +19,9 @@ use std::{
1619
};
1720

1821
use crate::{
19-
WeakActivityListener, ExecutorChannel, ExecutorRuntime, SpinConditions, WorkerChannel,
20-
RclrsError, WaitSetRunner, WaitSetRunConditions, Waitable, log_warn, log_debug, log_fatal,
21-
GuardCondition, ExecutorWorkerOptions, PayloadTask,
22+
log_debug, log_fatal, log_warn, ExecutorChannel, ExecutorRuntime, ExecutorWorkerOptions,
23+
GuardCondition, PayloadTask, RclrsError, SpinConditions, WaitSetRunConditions, WaitSetRunner,
24+
Waitable, WeakActivityListener, WorkerChannel,
2225
};
2326

2427
static FAILED_TO_SEND_WORKER: &'static str =
@@ -73,7 +76,11 @@ impl AllGuardConditions {
7376

7477
fn push(&self, guard_condition: Weak<GuardCondition>) {
7578
let mut inner = self.inner.lock().unwrap();
76-
if inner.iter().find(|other| guard_condition.ptr_eq(other)).is_some() {
79+
if inner
80+
.iter()
81+
.find(|other| guard_condition.ptr_eq(other))
82+
.is_some()
83+
{
7784
// This guard condition is already known
7885
return;
7986
}
@@ -115,11 +122,7 @@ impl ExecutorRuntime for BasicExecutorRuntime {
115122
// Use this to terminate the spinning once the wait set is finished.
116123
let workers_finished_clone = Arc::clone(&workers_finished);
117124
self.task_sender.add_async_task(Box::pin(async move {
118-
let workers = manage_workers(
119-
new_workers,
120-
all_guard_conditions,
121-
conditions,
122-
).await;
125+
let workers = manage_workers(new_workers, all_guard_conditions, conditions).await;
123126

124127
if let Err(err) = worker_result_sender.send(workers) {
125128
log_fatal!(
@@ -271,10 +274,7 @@ struct BasicExecutorChannel {
271274
}
272275

273276
impl ExecutorChannel for BasicExecutorChannel {
274-
fn create_worker(
275-
&self,
276-
options: ExecutorWorkerOptions,
277-
) -> Arc<dyn WorkerChannel> {
277+
fn create_worker(&self, options: ExecutorWorkerOptions) -> Arc<dyn WorkerChannel> {
278278
let runner = WaitSetRunner::new(options);
279279
let waitable_sender = runner.waitable_sender();
280280
let payload_task_sender = runner.payload_task_sender();
@@ -387,16 +387,19 @@ async fn manage_workers(
387387
mut new_workers: StreamFuture<UnboundedReceiver<WaitSetRunner>>,
388388
all_guard_conditions: AllGuardConditions,
389389
conditions: WaitSetRunConditions,
390-
) -> (Vec<WaitSetRunner>, StreamFuture<UnboundedReceiver<WaitSetRunner>>, Vec<RclrsError>) {
391-
let mut active_runners: Vec<oneshot::Receiver<(WaitSetRunner, Result<(), RclrsError>)>> = Vec::new();
390+
) -> (
391+
Vec<WaitSetRunner>,
392+
StreamFuture<UnboundedReceiver<WaitSetRunner>>,
393+
Vec<RclrsError>,
394+
) {
395+
let mut active_runners: Vec<oneshot::Receiver<(WaitSetRunner, Result<(), RclrsError>)>> =
396+
Vec::new();
392397
let mut finished_runners: Vec<WaitSetRunner> = Vec::new();
393398
let mut errors: Vec<RclrsError> = Vec::new();
394399

395-
let add_runner = |
396-
new_runner: Option<WaitSetRunner>,
397-
active_runners: &mut Vec<_>,
398-
finished_runners: &mut Vec<_>,
399-
| {
400+
let add_runner = |new_runner: Option<WaitSetRunner>,
401+
active_runners: &mut Vec<_>,
402+
finished_runners: &mut Vec<_>| {
400403
if let Some(runner) = new_runner {
401404
all_guard_conditions.push(Arc::downgrade(runner.guard_condition()));
402405
if conditions.halt_spinning.load(Ordering::Acquire) {
@@ -413,16 +416,10 @@ async fn manage_workers(
413416
add_runner(initial_worker, &mut active_runners, &mut finished_runners);
414417

415418
while !active_runners.is_empty() {
416-
let next_event = select(
417-
select_all(active_runners),
418-
new_workers,
419-
);
419+
let next_event = select(select_all(active_runners), new_workers);
420420

421421
match next_event.await {
422-
Either::Left((
423-
(finished_worker, _, remaining_workers),
424-
new_worker_stream,
425-
)) => {
422+
Either::Left(((finished_worker, _, remaining_workers), new_worker_stream)) => {
426423
match finished_worker {
427424
Ok((runner, result)) => {
428425
finished_runners.push(runner);
@@ -443,16 +440,13 @@ async fn manage_workers(
443440
active_runners = remaining_workers;
444441
new_workers = new_worker_stream;
445442
}
446-
Either::Right((
447-
(new_worker, new_worker_receiver),
448-
remaining_workers,
449-
)) => {
443+
Either::Right(((new_worker, new_worker_receiver), remaining_workers)) => {
450444
active_runners = remaining_workers.into_inner();
451445
add_runner(new_worker, &mut active_runners, &mut finished_runners);
452446
new_workers = new_worker_receiver.into_future();
453447
}
454448
}
455-
};
449+
}
456450

457451
(finished_runners, new_workers, errors)
458452
}

rclrs/src/node.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use rosidl_runtime_rs::Message;
3030

3131
use crate::{
3232
rcl_bindings::*, Client, ClientOptions, ClientState, Clock, ContextHandle, ExecutorCommands,
33-
LogParams, Logger, ParameterBuilder, ParameterInterface, ParameterVariant, Parameters, Promise,
34-
Publisher, PublisherOptions, PublisherState, RclrsError, Service, IntoAsyncServiceCallback,
35-
IntoNodeServiceCallback, ServiceOptions, ServiceState, Subscription, IntoAsyncSubscriptionCallback,
36-
IntoNodeSubscriptionCallback, SubscriptionOptions, SubscriptionState, TimeSource, ToLogParams,
37-
ENTITY_LIFECYCLE_MUTEX, Worker, WorkerOptions, WorkerState,
33+
IntoAsyncServiceCallback, IntoAsyncSubscriptionCallback, IntoNodeServiceCallback,
34+
IntoNodeSubscriptionCallback, LogParams, Logger, ParameterBuilder, ParameterInterface,
35+
ParameterVariant, Parameters, Promise, Publisher, PublisherOptions, PublisherState, RclrsError,
36+
Service, ServiceOptions, ServiceState, Subscription, SubscriptionOptions, SubscriptionState,
37+
TimeSource, ToLogParams, Worker, WorkerOptions, WorkerState, ENTITY_LIFECYCLE_MUTEX,
3838
};
3939

4040
/// A processing unit that can communicate with other nodes. See the API of
@@ -299,7 +299,9 @@ impl NodeState {
299299
Payload: 'static + Send + Sync,
300300
{
301301
let options = options.into();
302-
let commands = self.commands.create_worker_commands(Box::new(options.payload));
302+
let commands = self
303+
.commands
304+
.create_worker_commands(Box::new(options.payload));
303305
WorkerState::create(Arc::clone(self), commands)
304306
}
305307

rclrs/src/node/graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,4 +591,3 @@ mod tests {
591591
)));
592592
}
593593
}
594-

rclrs/src/node/node_options.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,3 @@ impl Drop for rcl_node_options_t {
476476
}
477477
}
478478
}
479-

rclrs/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::{
2+
any::Any,
23
boxed::Box,
34
ffi::{CStr, CString},
45
sync::{Arc, Mutex, MutexGuard},
5-
any::Any,
66
};
77

88
use rosidl_runtime_rs::{Message, Service as IdlService};
99

1010
use crate::{
11-
error::ToResult, rcl_bindings::*, WorkerCommands, IntoPrimitiveOptions, NodeHandle,
11+
error::ToResult, rcl_bindings::*, IntoPrimitiveOptions, MessageCow, Node, NodeHandle,
1212
QoSProfile, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclrsError, Waitable,
13-
WaitableLifecycle, ENTITY_LIFECYCLE_MUTEX, MessageCow, Node, Worker, WorkScope,
13+
WaitableLifecycle, WorkScope, Worker, WorkerCommands, ENTITY_LIFECYCLE_MUTEX,
1414
};
1515

1616
mod any_service_callback;

rclrs/src/service/any_service_callback.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use rosidl_runtime_rs::Service;
22

3-
use crate::{WorkerCommands, RclrsError, ServiceHandle, NodeServiceCallback, WorkerServiceCallback};
3+
use crate::{
4+
NodeServiceCallback, RclrsError, ServiceHandle, WorkerCommands, WorkerServiceCallback,
5+
};
46

57
use std::{any::Any, sync::Arc};
68

@@ -40,7 +42,9 @@ impl<T: Service> From<NodeServiceCallback<T>> for AnyServiceCallback<T, ()> {
4042
}
4143
}
4244

43-
impl<T: Service, Payload: 'static + Send> From<WorkerServiceCallback<T, Payload>> for AnyServiceCallback<T, Payload> {
45+
impl<T: Service, Payload: 'static + Send> From<WorkerServiceCallback<T, Payload>>
46+
for AnyServiceCallback<T, Payload>
47+
{
4448
fn from(value: WorkerServiceCallback<T, Payload>) -> Self {
4549
AnyServiceCallback::Worker(value)
4650
}

0 commit comments

Comments
 (0)