Skip to content

Commit a72ebd6

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

File tree

4 files changed

+64
-48
lines changed

4 files changed

+64
-48
lines changed

rclrs/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ impl Display for RclrsError {
5353
)
5454
}
5555
RclrsError::NegativeDuration(duration) => {
56-
write!(f, "A duration was negative when it should not have been: {duration:?}")
56+
write!(
57+
f,
58+
"A duration was negative when it should not have been: {duration:?}"
59+
)
5760
}
5861
}
5962
}

rclrs/src/node.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use rosidl_runtime_rs::Message;
1313

1414
pub use self::{builder::*, graph::*};
1515
use crate::{
16-
rcl_bindings::*, Client, ClientBase, Clock, Context, ContextHandle, GuardCondition, LogParams,
17-
Logger, ParameterBuilder, ParameterInterface, ParameterVariant, Parameters, Publisher,
18-
QoSProfile, RclrsError, Service, ServiceBase, Subscription, SubscriptionBase,
19-
SubscriptionCallback, TimeSource, Timer, IntoTimerOptions, AnyTimerCallback,
20-
TimerCallRepeating, TimerCallOnce, ToLogParams, ENTITY_LIFECYCLE_MUTEX,
16+
rcl_bindings::*, AnyTimerCallback, Client, ClientBase, Clock, Context, ContextHandle,
17+
GuardCondition, IntoTimerOptions, LogParams, Logger, ParameterBuilder, ParameterInterface,
18+
ParameterVariant, Parameters, Publisher, QoSProfile, RclrsError, Service, ServiceBase,
19+
Subscription, SubscriptionBase, SubscriptionCallback, TimeSource, Timer, TimerCallOnce,
20+
TimerCallRepeating, ToLogParams, ENTITY_LIFECYCLE_MUTEX,
2121
};
2222

2323
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
@@ -636,10 +636,7 @@ mod tests {
636636
.namespace("test_create_timer")
637637
.build()?;
638638

639-
let _timer = node.create_timer_repeating(
640-
Duration::from_millis(1),
641-
|| { }
642-
)?;
639+
let _timer = node.create_timer_repeating(Duration::from_millis(1), || {})?;
643640
assert_eq!(node.live_timers().len(), 1);
644641

645642
Ok(())

rclrs/src/timer.rs

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::{
2-
clock::Clock,
3-
context::ContextHandle,
4-
error::RclrsError,
5-
rcl_bindings::*,
6-
ToResult, log_error, ToLogParams, ENTITY_LIFECYCLE_MUTEX,
2+
clock::Clock, context::ContextHandle, error::RclrsError, log_error, rcl_bindings::*,
3+
ToLogParams, ToResult, ENTITY_LIFECYCLE_MUTEX,
74
};
85
// TODO: fix me when the callback type is properly defined.
96
// use std::fmt::Debug;
@@ -58,7 +55,8 @@ impl Timer {
5855
unsafe {
5956
let rcl_timer = self.handle.rcl_timer.lock().unwrap();
6057
rcl_timer_get_period(&*rcl_timer, &mut timer_period_ns)
61-
}.ok()?;
58+
}
59+
.ok()?;
6260

6361
rcl_duration(timer_period_ns)
6462
}
@@ -76,7 +74,8 @@ impl Timer {
7674
unsafe {
7775
let rcl_timer = self.handle.rcl_timer.lock().unwrap();
7876
rcl_timer_is_canceled(&*rcl_timer, &mut is_canceled)
79-
}.ok()?;
77+
}
78+
.ok()?;
8079
Ok(is_canceled)
8180
}
8281

@@ -86,7 +85,8 @@ impl Timer {
8685
unsafe {
8786
let rcl_timer = self.handle.rcl_timer.lock().unwrap();
8887
rcl_timer_get_time_since_last_call(&*rcl_timer, &mut time_value_ns)
89-
}.ok()?;
88+
}
89+
.ok()?;
9090

9191
rcl_duration(time_value_ns)
9292
}
@@ -97,7 +97,8 @@ impl Timer {
9797
unsafe {
9898
let rcl_timer = self.handle.rcl_timer.lock().unwrap();
9999
rcl_timer_get_time_until_next_call(&*rcl_timer, &mut time_value_ns)
100-
}.ok()?;
100+
}
101+
.ok()?;
101102

102103
rcl_duration(time_value_ns)
103104
}
@@ -137,7 +138,10 @@ impl Timer {
137138
/// See also:
138139
/// * [`Self::set_oneshot`]
139140
/// * [`Self::remove_callback`]
140-
pub fn set_repeating<Args>(&self, f: impl TimerCallRepeating<Args>) -> Option<AnyTimerCallback> {
141+
pub fn set_repeating<Args>(
142+
&self,
143+
f: impl TimerCallRepeating<Args>,
144+
) -> Option<AnyTimerCallback> {
141145
self.set_callback(f.into_repeating_timer_callback())
142146
}
143147

@@ -188,7 +192,7 @@ impl Timer {
188192

189193
let rcl_timer = Arc::new(Mutex::new(
190194
// SAFETY: Zero-initializing a timer is always safe
191-
unsafe { rcl_get_zero_initialized_timer() }
195+
unsafe { rcl_get_zero_initialized_timer() },
192196
));
193197

194198
unsafe {
@@ -209,7 +213,8 @@ impl Timer {
209213
rcl_timer_callback,
210214
allocator,
211215
)
212-
}.ok()?;
216+
}
217+
.ok()?;
213218

214219
let timer = Timer {
215220
handle: TimerHandle { rcl_timer, clock },
@@ -249,10 +254,7 @@ impl Timer {
249254
}
250255

251256
if let Err(err) = self.rcl_call() {
252-
log_error!(
253-
"timer",
254-
"Unable to call timer: {err:?}",
255-
);
257+
log_error!("timer", "Unable to call timer: {err:?}",);
256258
}
257259

258260
Ok(())
@@ -310,7 +312,10 @@ unsafe impl Send for rcl_timer_t {}
310312
#[cfg(test)]
311313
mod tests {
312314
use crate::*;
313-
use std::{thread, time, sync::atomic::{AtomicBool, Ordering}};
315+
use std::{
316+
sync::atomic::{AtomicBool, Ordering},
317+
thread, time,
318+
};
314319

315320
#[test]
316321
fn traits() {
@@ -327,7 +332,7 @@ mod tests {
327332
&context.handle,
328333
Duration::from_millis(1),
329334
Clock::system(),
330-
(|| { }).into_repeating_timer_callback(),
335+
(|| {}).into_repeating_timer_callback(),
331336
);
332337
assert!(result.is_ok());
333338
}
@@ -339,7 +344,7 @@ mod tests {
339344
&context.handle,
340345
Duration::from_millis(1),
341346
Clock::steady(),
342-
(|| { }).into_repeating_timer_callback(),
347+
(|| {}).into_repeating_timer_callback(),
343348
);
344349
assert!(result.is_ok());
345350
}
@@ -360,7 +365,7 @@ mod tests {
360365
&context.handle,
361366
Duration::from_millis(1),
362367
clock,
363-
(|| { }).into_repeating_timer_callback(),
368+
(|| {}).into_repeating_timer_callback(),
364369
);
365370
assert!(result.is_ok());
366371
}
@@ -374,7 +379,7 @@ mod tests {
374379
&context.handle,
375380
period,
376381
Clock::steady(),
377-
(|| { }).into_repeating_timer_callback(),
382+
(|| {}).into_repeating_timer_callback(),
378383
);
379384

380385
let timer = result.unwrap();
@@ -390,7 +395,7 @@ mod tests {
390395
&context.handle,
391396
Duration::from_millis(1),
392397
Clock::steady(),
393-
(|| { }).into_repeating_timer_callback(),
398+
(|| {}).into_repeating_timer_callback(),
394399
);
395400

396401
let timer = result.unwrap();
@@ -407,7 +412,7 @@ mod tests {
407412
&context.handle,
408413
Duration::from_millis(2),
409414
Clock::steady(),
410-
(|| { }).into_repeating_timer_callback(),
415+
(|| {}).into_repeating_timer_callback(),
411416
);
412417
let timer = result.unwrap();
413418

@@ -432,7 +437,7 @@ mod tests {
432437
&context.handle,
433438
period,
434439
Clock::steady(),
435-
(|| { }).into_repeating_timer_callback(),
440+
(|| {}).into_repeating_timer_callback(),
436441
);
437442
let timer = result.unwrap();
438443

@@ -453,8 +458,9 @@ mod tests {
453458
&context.handle,
454459
period,
455460
Clock::steady(),
456-
(|| { }).into_repeating_timer_callback(),
457-
).unwrap();
461+
(|| {}).into_repeating_timer_callback(),
462+
)
463+
.unwrap();
458464

459465
// The unwrap will panic if the remaining time is negative
460466
timer.time_until_next_call().unwrap();
@@ -463,7 +469,10 @@ mod tests {
463469
thread::sleep(Duration::from_millis(3));
464470

465471
// Now the time until next call should give an error
466-
assert!(matches!(timer.time_until_next_call(), Err(RclrsError::NegativeDuration(_))));
472+
assert!(matches!(
473+
timer.time_until_next_call(),
474+
Err(RclrsError::NegativeDuration(_))
475+
));
467476

468477
// Reset the timer so its interval begins again
469478
assert!(timer.reset().is_ok());
@@ -479,8 +488,9 @@ mod tests {
479488
&context.handle,
480489
Duration::from_millis(1),
481490
Clock::steady(),
482-
(|| { }).into_repeating_timer_callback(),
483-
).unwrap();
491+
(|| {}).into_repeating_timer_callback(),
492+
)
493+
.unwrap();
484494

485495
// The unwrap will panic if the remaining time is negative
486496
timer.time_until_next_call().unwrap();
@@ -489,7 +499,10 @@ mod tests {
489499
thread::sleep(time::Duration::from_micros(1500));
490500

491501
// Now the time until the next call should give an error
492-
assert!(matches!(timer.time_until_next_call(), Err(RclrsError::NegativeDuration(_))));
502+
assert!(matches!(
503+
timer.time_until_next_call(),
504+
Err(RclrsError::NegativeDuration(_))
505+
));
493506

494507
// The unwrap will panic if anything went wrong with the call
495508
timer.rcl_call().unwrap();
@@ -505,8 +518,9 @@ mod tests {
505518
&context.handle,
506519
Duration::from_millis(1),
507520
Clock::steady(),
508-
(|| { }).into_repeating_timer_callback(),
509-
).unwrap();
521+
(|| {}).into_repeating_timer_callback(),
522+
)
523+
.unwrap();
510524

511525
assert!(!timer.is_ready().unwrap());
512526

@@ -580,8 +594,11 @@ mod tests {
580594
executed: Arc<AtomicBool>,
581595
) -> AnyTimerCallback {
582596
(move |t: Time| {
583-
assert!(t.compare_with(&initial_time, |t, initial| t >= initial).unwrap());
597+
assert!(t
598+
.compare_with(&initial_time, |t, initial| t >= initial)
599+
.unwrap());
584600
executed.store(true, Ordering::Release);
585-
}).into_oneshot_timer_callback()
601+
})
602+
.into_oneshot_timer_callback()
586603
}
587604
}

rclrs/src/wait.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ impl WaitSet {
465465
#[cfg(test)]
466466
mod tests {
467467
use super::*;
468-
use crate::clock::Clock;
469-
use crate::timer::*;
468+
use crate::{clock::Clock, timer::*};
470469

471470
#[test]
472471
fn traits() {
@@ -499,7 +498,7 @@ mod tests {
499498
&context.handle,
500499
Duration::from_millis(1),
501500
Clock::steady(),
502-
(|| { }).into_repeating_timer_callback(),
501+
(|| {}).into_repeating_timer_callback(),
503502
)?);
504503

505504
let mut wait_set = WaitSet::new(0, 0, 1, 0, 0, 0, &context)?;
@@ -518,7 +517,7 @@ mod tests {
518517
&context.handle,
519518
Duration::from_millis(1),
520519
Clock::steady(),
521-
(|| { }).into_repeating_timer_callback(),
520+
(|| {}).into_repeating_timer_callback(),
522521
)?);
523522

524523
let mut wait_set = WaitSet::new(0, 0, 1, 0, 0, 0, &context)?;

0 commit comments

Comments
 (0)