@@ -19,7 +19,7 @@ use std::{
1919use rosidl_runtime_rs:: Message ;
2020
2121use crate :: {
22- rcl_bindings:: * , Client , ClientBase , Clock , ContextHandle , GuardCondition ,
22+ rcl_bindings:: * , Client , ClientBase , ClientOptions , Clock , ContextHandle , GuardCondition ,
2323 ParameterBuilder , ParameterInterface , ParameterVariant , Parameters , Publisher , PublisherOptions ,
2424 RclrsError , Service , ServiceBase , ServiceOptions , Subscription , SubscriptionBase , SubscriptionCallback ,
2525 SubscriptionOptions , TimeSource , ENTITY_LIFECYCLE_MUTEX ,
@@ -215,13 +215,47 @@ impl NodeState {
215215
216216 /// Creates a [`Client`][1].
217217 ///
218+ /// Pass in only the service name for the `options` argument to use all default client options:
219+ /// ```
220+ /// # use rclrs::*;
221+ /// # let executor = Context::default().create_basic_executor();
222+ /// # let node = executor.create_node("my_node").unwrap();
223+ /// let client = node.create_client::<test_msgs::srv::Empty>(
224+ /// "my_service"
225+ /// )
226+ /// .unwrap();
227+ /// ```
228+ ///
229+ /// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
230+ /// client options:
231+ ///
232+ /// ```
233+ /// # use rclrs::*;
234+ /// # let executor = Context::default().create_basic_executor();
235+ /// # let node = executor.create_node("my_node").unwrap();
236+ /// let client = node.create_client::<test_msgs::srv::Empty>(
237+ /// "my_service"
238+ /// .keep_all()
239+ /// .transient_local()
240+ /// )
241+ /// .unwrap();
242+ /// ```
243+ ///
244+ /// Any quality of service options that you explicitly specify will override
245+ /// the default service options. Any that you do not explicitly specify will
246+ /// remain the default service options. Note that clients are generally
247+ /// expected to use [reliable][2], so it's best not to change the reliability
248+ /// setting unless you know what you are doing.
218249 /// [1]: crate::Client
219250 // TODO: make client's lifetime depend on node's lifetime
220- pub fn create_client < T > ( & self , topic : & str ) -> Result < Arc < Client < T > > , RclrsError >
251+ pub fn create_client < ' a , T > (
252+ & self ,
253+ options : impl Into < ClientOptions < ' a > > ,
254+ ) -> Result < Arc < Client < T > > , RclrsError >
221255 where
222256 T : rosidl_runtime_rs:: Service ,
223257 {
224- let client = Arc :: new ( Client :: < T > :: new ( Arc :: clone ( & self . handle ) , topic ) ?) ;
258+ let client = Arc :: new ( Client :: < T > :: new ( Arc :: clone ( & self . handle ) , options ) ?) ;
225259 { self . clients_mtx . lock ( ) . unwrap ( ) } . push ( Arc :: downgrade ( & client) as Weak < dyn ClientBase > ) ;
226260 Ok ( client)
227261 }
@@ -352,7 +386,7 @@ impl NodeState {
352386 /// Any quality of service options that you explicitly specify will override
353387 /// the default service options. Any that you do not explicitly specify will
354388 /// remain the default service options. Note that services are generally
355- /// expected to use [reliable][2], so is best not to change the reliability
389+ /// expected to use [reliable][2], so it's best not to change the reliability
356390 /// setting unless you know what you are doing.
357391 ///
358392 /// [1]: crate::Service
0 commit comments