Skip to content

Commit c7f78ee

Browse files
committed
Update documentation for create_publisher
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 2dff995 commit c7f78ee

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

rclrs/src/node.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,39 @@ impl NodeState {
269269

270270
/// Creates a [`Publisher`][1].
271271
///
272+
/// Pass in only the topic name for the `options` argument to use all default publisher options:
273+
/// ```
274+
/// # use rclrs::*;
275+
/// # let executor = Context::default().create_basic_executor();
276+
/// # let node = executor.create_node("my_node").unwrap();
277+
/// let publisher = node.create_publisher::<test_msgs::msg::Empty>(
278+
/// "my_topic"
279+
/// )
280+
/// .unwrap();
281+
/// ```
282+
///
283+
/// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
284+
/// publisher options:
285+
///
286+
/// ```
287+
/// # use rclrs::*;
288+
/// # let executor = Context::default().create_basic_executor();
289+
/// # let node = executor.create_node("my_node").unwrap();
290+
/// let publisher = node.create_publisher::<test_msgs::msg::Empty>(
291+
/// "my_topic"
292+
/// .keep_last(100)
293+
/// .transient_local()
294+
/// )
295+
/// .unwrap();
296+
///
297+
/// let reliable_publisher = node.create_publisher::<test_msgs::msg::Empty>(
298+
/// "my_topic"
299+
/// .reliable()
300+
/// )
301+
/// .unwrap();
302+
/// ```
303+
///
272304
/// [1]: crate::Publisher
273-
// TODO: make publisher's lifetime depend on node's lifetime
274305
pub fn create_publisher<'a, T>(
275306
&self,
276307
options: impl Into<PublisherOptions<'a>>,
@@ -295,7 +326,8 @@ impl NodeState {
295326
/// println!("Received request!");
296327
/// test_msgs::srv::Empty_Response::default()
297328
/// },
298-
/// );
329+
/// )
330+
/// .unwrap();
299331
/// ```
300332
///
301333
/// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
@@ -313,7 +345,8 @@ impl NodeState {
313345
/// println!("Received request!");
314346
/// test_msgs::srv::Empty_Response::default()
315347
/// },
316-
/// );
348+
/// )
349+
/// .unwrap();
317350
/// ```
318351
///
319352
/// Any quality of service options that you explicitly specify will override
@@ -356,7 +389,8 @@ impl NodeState {
356389
/// |_msg: test_msgs::msg::Empty| {
357390
/// println!("Received message!");
358391
/// },
359-
/// );
392+
/// )
393+
/// .unwrap();
360394
/// ```
361395
///
362396
/// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
@@ -373,15 +407,17 @@ impl NodeState {
373407
/// |_msg: test_msgs::msg::Empty| {
374408
/// println!("Received message!");
375409
/// },
376-
/// );
410+
/// )
411+
/// .unwrap();
377412
///
378413
/// let reliable_subscription = node.create_subscription(
379414
/// "my_reliable_topic"
380415
/// .reliable(),
381416
/// |_msg: test_msgs::msg::Empty| {
382417
/// println!("Received message!");
383418
/// },
384-
/// );
419+
/// )
420+
/// .unwrap();
385421
/// ```
386422
///
387423
/// [1]: crate::Subscription

0 commit comments

Comments
 (0)