@@ -21,7 +21,7 @@ use rosidl_runtime_rs::Message;
2121use crate :: {
2222 rcl_bindings:: * , Client , ClientBase , Clock , ContextHandle , GuardCondition ,
2323 ParameterBuilder , ParameterInterface , ParameterVariant , Parameters , Publisher , PublisherOptions ,
24- RclrsError , Service , ServiceBase , Subscription , SubscriptionBase , SubscriptionCallback ,
24+ RclrsError , Service , ServiceBase , ServiceOptions , Subscription , SubscriptionBase , SubscriptionCallback ,
2525 SubscriptionOptions , TimeSource , ENTITY_LIFECYCLE_MUTEX ,
2626} ;
2727
@@ -284,11 +284,50 @@ impl NodeState {
284284
285285 /// Creates a [`Service`][1].
286286 ///
287+ /// Pass in only the service name for the `options` argument to use all default service options:
288+ /// ```
289+ /// # use rclrs::*;
290+ /// # let executor = Context::default().create_basic_executor();
291+ /// # let node = executor.create_node("my_node").unwrap();
292+ /// let service = node.create_service::<test_msgs::srv::Empty, _>(
293+ /// "my_service",
294+ /// |_info, _request| {
295+ /// println!("Received request!");
296+ /// test_msgs::srv::Empty_Response::default()
297+ /// },
298+ /// );
299+ /// ```
300+ ///
301+ /// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
302+ /// service options:
303+ ///
304+ /// ```
305+ /// # use rclrs::*;
306+ /// # let executor = Context::default().create_basic_executor();
307+ /// # let node = executor.create_node("my_node").unwrap();
308+ /// let service = node.create_service::<test_msgs::srv::Empty, _>(
309+ /// "my_service"
310+ /// .keep_all()
311+ /// .transient_local(),
312+ /// |_info, _request| {
313+ /// println!("Received request!");
314+ /// test_msgs::srv::Empty_Response::default()
315+ /// },
316+ /// );
317+ /// ```
318+ ///
319+ /// Any quality of service options that you explicitly specify will override
320+ /// the default service options. Any that you do not explicitly specify will
321+ /// remain the default service options. Note that services are generally
322+ /// expected to use [reliable][2], so is best not to change the reliability
323+ /// setting unless you know what you are doing.
324+ ///
287325 /// [1]: crate::Service
326+ /// [2]: crate::QoSReliabilityPolicy::Reliable
288327 // TODO: make service's lifetime depend on node's lifetime
289- pub fn create_service < T , F > (
328+ pub fn create_service < ' a , T , F > (
290329 & self ,
291- topic : & str ,
330+ options : impl Into < ServiceOptions < ' a > > ,
292331 callback : F ,
293332 ) -> Result < Arc < Service < T > > , RclrsError >
294333 where
@@ -297,7 +336,7 @@ impl NodeState {
297336 {
298337 let service = Arc :: new ( Service :: < T > :: new (
299338 Arc :: clone ( & self . handle ) ,
300- topic ,
339+ options ,
301340 callback,
302341 ) ?) ;
303342 { self . services_mtx . lock ( ) . unwrap ( ) }
@@ -313,22 +352,22 @@ impl NodeState {
313352 /// # let executor = Context::default().create_basic_executor();
314353 /// # let node = executor.create_node("my_node").unwrap();
315354 /// let subscription = node.create_subscription(
316- /// "my_subscription ",
355+ /// "my_topic ",
317356 /// |_msg: test_msgs::msg::Empty| {
318357 /// println!("Received message!");
319358 /// },
320359 /// );
321360 /// ```
322361 ///
323- /// Take advantage of [`IntoPrimitiveOptions`] to easily build up the
362+ /// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
324363 /// subscription options:
325364 ///
326365 /// ```
327366 /// # use rclrs::*;
328367 /// # let executor = Context::default().create_basic_executor();
329368 /// # let node = executor.create_node("my_node").unwrap();
330369 /// let subscription = node.create_subscription(
331- /// "my_subscription "
370+ /// "my_topic "
332371 /// .keep_last(100)
333372 /// .transient_local(),
334373 /// |_msg: test_msgs::msg::Empty| {
@@ -337,7 +376,7 @@ impl NodeState {
337376 /// );
338377 ///
339378 /// let reliable_subscription = node.create_subscription(
340- /// "my_reliable_subscription "
379+ /// "my_reliable_topic "
341380 /// .reliable(),
342381 /// |_msg: test_msgs::msg::Empty| {
343382 /// println!("Received message!");
0 commit comments