@@ -75,9 +75,70 @@ impl<'a> ActionClientOptions<'a> {
7575 }
7676}
7777
78- impl < ' a , T : Borrow < str > + ?Sized + ' a > From < & ' a T > for ActionClientOptions < ' a > {
79- fn from ( value : & ' a T ) -> Self {
80- Self :: new ( value. borrow ( ) )
78+ /// Trait to implicitly convert a compatible object into [`ActionClientOptions`].
79+ pub trait IntoActionClientOptions < ' a > : Sized {
80+ /// Change this into an [`ActionClientOptions`].
81+ fn into_action_client_options ( self ) -> ActionClientOptions < ' a > ;
82+
83+ /// Set the quality of service profile for the goal service
84+ fn goal_service_qos ( self , profile : QoSProfile ) -> ActionClientOptions < ' a > {
85+ let mut options = self . into_action_client_options ( ) ;
86+ options. goal_service_qos = profile;
87+ options
88+ }
89+
90+ /// Set the quality of service profile for the result service
91+ fn result_service_qos ( self , profile : QoSProfile ) -> ActionClientOptions < ' a > {
92+ let mut options = self . into_action_client_options ( ) ;
93+ options. result_service_qos = profile;
94+ options
95+ }
96+
97+ /// Set the quality of service profile for the cancel service
98+ fn cancel_service_qos ( self , profile : QoSProfile ) -> ActionClientOptions < ' a > {
99+ let mut options = self . into_action_client_options ( ) ;
100+ options. cancel_service_qos = profile;
101+ options
102+ }
103+
104+ /// Set the quality of service profile for the feedback topic
105+ fn feedback_topic_qos ( self , profile : QoSProfile ) -> ActionClientOptions < ' a > {
106+ let mut options = self . into_action_client_options ( ) ;
107+ options. feedback_topic_qos = profile;
108+ options
109+ }
110+
111+ /// Set the quality of service profile for the status topic
112+ fn status_topic_qos ( self , profile : QoSProfile ) -> ActionClientOptions < ' a > {
113+ let mut options = self . into_action_client_options ( ) ;
114+ options. status_topic_qos = profile;
115+ options
116+ }
117+ }
118+
119+ impl < ' a , T : Borrow < str > + ?Sized + ' a > IntoActionClientOptions < ' a > for & ' a T {
120+ fn into_action_client_options ( self ) -> ActionClientOptions < ' a > {
121+ ActionClientOptions :: new ( self . borrow ( ) )
122+ }
123+ }
124+
125+ impl < ' a > IntoActionClientOptions < ' a > for ActionClientOptions < ' a > {
126+ fn into_action_client_options ( self ) -> ActionClientOptions < ' a > {
127+ self
128+ }
129+ }
130+
131+ impl < ' a > From < & ' _ ActionClientOptions < ' a > > for rcl_action_client_options_t {
132+ fn from ( value : & ' _ ActionClientOptions < ' a > ) -> Self {
133+ rcl_action_client_options_s {
134+ goal_service_qos : value. goal_service_qos . into ( ) ,
135+ result_service_qos : value. result_service_qos . into ( ) ,
136+ cancel_service_qos : value. cancel_service_qos . into ( ) ,
137+ feedback_topic_qos : value. feedback_topic_qos . into ( ) ,
138+ status_topic_qos : value. status_topic_qos . into ( ) ,
139+ // SAFETY: No preconditions for this function
140+ allocator : unsafe { rcutils_get_default_allocator ( ) } ,
141+ }
81142 }
82143}
83144
@@ -225,9 +286,9 @@ impl<A: Action> ActionClientState<A> {
225286 /// Creates a new action client.
226287 pub ( crate ) fn create < ' a > (
227288 node : & Node ,
228- options : impl Into < ActionClientOptions < ' a > > ,
289+ options : impl IntoActionClientOptions < ' a > ,
229290 ) -> Result < Arc < Self > , RclrsError > {
230- let options = options. into ( ) ;
291+ let options = options. into_action_client_options ( ) ;
231292 // SAFETY: Getting a zero-initialized value is always safe.
232293 let mut rcl_action_client = unsafe { rcl_action_get_zero_initialized_client ( ) } ;
233294 let type_support = A :: get_type_support ( ) as * const rosidl_action_type_support_t ;
@@ -238,7 +299,7 @@ impl<A: Action> ActionClientState<A> {
238299 } ) ?;
239300
240301 // SAFETY: No preconditions for this function.
241- let action_client_options = unsafe { rcl_action_client_get_default_options ( ) } ;
302+ let action_client_options = ( & options ) . into ( ) ;
242303
243304 {
244305 let mut rcl_node = node. handle ( ) . rcl_node . lock ( ) . unwrap ( ) ;
0 commit comments