Skip to content

Commit 1986ebb

Browse files
committed
Fix formatting for examples
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 7eba15d commit 1986ebb

File tree

11 files changed

+38
-75
lines changed

11 files changed

+38
-75
lines changed

examples/logging_demo/src/main.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,16 @@ fn main() -> Result<(), RclrsError> {
1212

1313
// You can apply modifiers such as .once() to node.logger()
1414
// to dictate how the logging behaves.
15-
log!(
16-
node.logger().once(),
17-
"First message: {data}",
18-
);
15+
log!(node.logger().once(), "First message: {data}",);
1916

20-
log!(
21-
node.logger().skip_first(),
22-
"Subsequent message: {data}",
23-
);
17+
log!(node.logger().skip_first(), "Subsequent message: {data}",);
2418

2519
// You can chain multiple modifiers together.
2620
log_warn!(
27-
node
28-
.logger()
29-
.skip_first()
30-
.throttle(Duration::from_secs(5)),
21+
node.logger().skip_first().throttle(Duration::from_secs(5)),
3122
"Throttled message: {data}",
3223
);
33-
}
24+
},
3425
)?;
3526

3627
// Any &str can be used as the logger name and have

examples/minimal_client_service/src/minimal_client.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{Error, Result};
2-
use rclrs::*;
32
use example_interfaces::srv::*;
3+
use rclrs::*;
44

55
fn main() -> Result<(), Error> {
66
let mut executor = Context::default_from_env()?.create_basic_executor();
@@ -16,8 +16,7 @@ fn main() -> Result<(), Error> {
1616
let request = AddTwoInts_Request { a: 41, b: 1 };
1717

1818
println!("Waiting for response");
19-
let response: AddTwoInts_Response =
20-
client.call(&request).unwrap().await.unwrap();
19+
let response: AddTwoInts_Response = client.call(&request).unwrap().await.unwrap();
2120

2221
println!(
2322
"Result of {} + {} is: {}",

examples/minimal_client_service/src/minimal_client_async.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{Error, Result};
2-
use rclrs::*;
32
use example_interfaces::srv::*;
3+
use rclrs::*;
44

55
#[tokio::main]
66
async fn main() -> Result<(), Error> {
@@ -18,15 +18,14 @@ async fn main() -> Result<(), Error> {
1818

1919
let request = AddTwoInts_Request { a: 41, b: 1 };
2020

21-
let promise = client.call_then(
22-
&request,
23-
move |response: AddTwoInts_Response| {
21+
let promise = client
22+
.call_then(&request, move |response: AddTwoInts_Response| {
2423
println!(
2524
"Result of {} + {} is: {}",
2625
request.a, request.b, response.sum,
2726
);
28-
}
29-
).unwrap();
27+
})
28+
.unwrap();
3029

3130
println!("Waiting for response");
3231
executor
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use anyhow::{Error, Result};
2-
use rclrs::*;
32
use example_interfaces::srv::*;
3+
use rclrs::*;
44

5-
fn handle_service(
6-
request: AddTwoInts_Request,
7-
info: ServiceInfo,
8-
) -> AddTwoInts_Response {
5+
fn handle_service(request: AddTwoInts_Request, info: ServiceInfo) -> AddTwoInts_Response {
96
let timestamp = info
107
.received_timestamp
118
.map(|t| format!(" at [{t:?}]"))
@@ -22,12 +19,9 @@ fn main() -> Result<(), Error> {
2219

2320
let node = executor.create_node("minimal_service")?;
2421

25-
let _server = node
26-
.create_service::<AddTwoInts, _>("add_two_ints", handle_service)?;
22+
let _server = node.create_service::<AddTwoInts, _>("add_two_ints", handle_service)?;
2723

2824
println!("Starting server");
29-
executor
30-
.spin(SpinOptions::default())
31-
.first_error()?;
25+
executor.spin(SpinOptions::default()).first_error()?;
3226
Ok(())
3327
}

examples/minimal_pub_sub/src/minimal_subscriber.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ fn main() -> Result<(), Error> {
1717
)?;
1818

1919
println!("Waiting for messages...");
20-
executor
21-
.spin(SpinOptions::default())
22-
.first_error()?;
20+
executor.spin(SpinOptions::default()).first_error()?;
2321
Ok(())
2422
}

examples/minimal_pub_sub/src/minimal_two_nodes.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ impl MinimalSubscriberNode {
1717
pub fn new(executor: &Executor, name: &str, topic: &str) -> Result<Self, RclrsError> {
1818
let node = executor.create_node(name)?;
1919

20-
let worker = node.create_worker::<SubscriptionData>(
21-
SubscriptionData {
22-
node: Arc::clone(&node),
23-
num_messages: 0,
24-
}
25-
);
20+
let worker = node.create_worker::<SubscriptionData>(SubscriptionData {
21+
node: Arc::clone(&node),
22+
num_messages: 0,
23+
});
2624

2725
let subscription = worker.create_subscription(
2826
topic,
@@ -34,7 +32,7 @@ impl MinimalSubscriberNode {
3432
data.node.name(),
3533
data.num_messages,
3634
);
37-
}
35+
},
3836
)?;
3937

4038
Ok(MinimalSubscriberNode { subscription })
@@ -66,9 +64,6 @@ fn main() -> Result<(), Error> {
6664
}
6765
});
6866

69-
executor
70-
.spin(rclrs::SpinOptions::default())
71-
.first_error()?;
67+
executor.spin(rclrs::SpinOptions::default()).first_error()?;
7268
Ok(())
7369
}
74-

examples/minimal_pub_sub/src/zero_copy_subscriber.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ fn main() -> Result<(), Error> {
99
let worker = node.create_worker::<usize>(0);
1010
let _subscription = worker.create_subscription::<example_interfaces::msg::UInt32, _>(
1111
"topic",
12-
move |num_messages: &mut usize, msg: ReadOnlyLoanedMessage<example_interfaces::msg::UInt32>| {
12+
move |num_messages: &mut usize,
13+
msg: ReadOnlyLoanedMessage<example_interfaces::msg::UInt32>| {
1314
*num_messages += 1;
1415
println!("I heard: '{}'", msg.data);
1516
println!("(Got {} messages so far)", *num_messages);
1617
},
1718
)?;
1819

19-
executor
20-
.spin(SpinOptions::default())
21-
.first_error()?;
20+
executor.spin(SpinOptions::default()).first_error()?;
2221
Ok(())
2322
}

examples/parameter_demo/src/main.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ fn main() -> Result<(), RclrsError> {
1010
.default("Hello".into())
1111
.mandatory()?;
1212

13-
let _subscription = node.create_subscription(
14-
"greet",
15-
move |msg: example_interfaces::msg::String| {
13+
let _subscription =
14+
node.create_subscription("greet", move |msg: example_interfaces::msg::String| {
1615
println!("{}, {}", greeting.get(), msg.data);
17-
}
18-
)?;
16+
})?;
1917

2018
println!(
2119
"Ready to provide a greeting. \

examples/rust_pubsub/src/simple_publisher.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ struct SimplePublisherNode {
99
impl SimplePublisherNode {
1010
fn new(executor: &Executor) -> Result<Self, RclrsError> {
1111
let node = executor.create_node("simple_publisher").unwrap();
12-
let publisher = node
13-
.create_publisher("publish_hello")
14-
.unwrap();
12+
let publisher = node.create_publisher("publish_hello").unwrap();
1513
Ok(Self { publisher })
1614
}
1715

examples/rust_pubsub/src/simple_subscriber.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use rclrs::*;
2-
use std::{
3-
thread,
4-
time::Duration,
5-
};
2+
use std::{thread, time::Duration};
63
use std_msgs::msg::String as StringMsg;
74

85
pub struct SimpleSubscriptionNode {

examples/worker_demo/src/main.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() -> Result<(), RclrsError> {
1212
"input_topic",
1313
move |data: &mut String, msg: example_interfaces::msg::String| {
1414
*data = msg.data;
15-
}
15+
},
1616
)?;
1717

1818
// // Use this timer-based implementation when timers are available instead
@@ -28,20 +28,15 @@ fn main() -> Result<(), RclrsError> {
2828
// }
2929
// )?;
3030

31-
std::thread::spawn(move || {
32-
loop {
33-
std::thread::sleep(std::time::Duration::from_secs(1));
34-
let publisher = Arc::clone(&publisher);
35-
let _ = worker.run(move |data: &mut String| {
36-
let msg = example_interfaces::msg::String {
37-
data: data.clone()
38-
};
39-
publisher.publish(msg).unwrap();
40-
});
41-
}
31+
std::thread::spawn(move || loop {
32+
std::thread::sleep(std::time::Duration::from_secs(1));
33+
let publisher = Arc::clone(&publisher);
34+
let _ = worker.run(move |data: &mut String| {
35+
let msg = example_interfaces::msg::String { data: data.clone() };
36+
publisher.publish(msg).unwrap();
37+
});
4238
});
4339

44-
4540
println!(
4641
"Beginning repeater... \n >> \
4742
Publish a std_msg::msg::String to \"input_topic\" and we will periodically republish it to \"output_topic\".\n\n\

0 commit comments

Comments
 (0)