Skip to content

Commit

Permalink
Fix format for the example.
Browse files Browse the repository at this point in the history
Signed-off-by: Agustin Alba Chicar <[email protected]>
  • Loading branch information
agalbachicar committed Dec 1, 2024
1 parent fbb8629 commit ab3d63a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions examples/rclrs_timer_demo/src/rclrs_timer_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
/// that prints the timer callback execution iteration. The callback is executed
/// thanks to the spin, which is in charge of executing the timer's events among
/// other entities' events.
use rclrs::{create_node, Context, Node, Timer, RclrsError};
use std::{env, sync::{Arc, Mutex}};
use rclrs::{create_node, Context, Node, RclrsError, Timer};
use std::{
env,
sync::{Arc, Mutex},
};

/// Contains both the node and timer.
struct SimpleTimerNode {
Expand All @@ -12,7 +15,6 @@ struct SimpleTimerNode {
}

impl SimpleTimerNode {

/// Creates a node and a timer with a callback.
///
/// The callback will simply print to stdout:
Expand All @@ -26,7 +28,10 @@ impl SimpleTimerNode {
context,
Some(Box::new(move |_| {
let x = *count.lock().unwrap();
println!("Drinking 🧉 for the {}th time every {} nanoseconds.", x, timer_period_ns);
println!(
"Drinking 🧉 for the {}th time every {} nanoseconds.",
x, timer_period_ns
);
*count.lock().unwrap() = x + 1;
})),
None,
Expand All @@ -35,10 +40,9 @@ impl SimpleTimerNode {
}
}


fn main() -> Result<(), RclrsError> {
let timer_period: i64 = 1e9 as i64; // 1 seconds.
let context = Context::new(env::args()).unwrap();
let simple_timer_node = Arc::new(SimpleTimerNode::new(&context, timer_period).unwrap());
rclrs::spin(simple_timer_node.node.clone())
}
}

0 comments on commit ab3d63a

Please sign in to comment.