File tree Expand file tree Collapse file tree 4 files changed +45
-19
lines changed Expand file tree Collapse file tree 4 files changed +45
-19
lines changed Original file line number Diff line number Diff line change @@ -293,12 +293,19 @@ pub struct ClientOptions<'a> {
293293 pub qos : QoSProfile ,
294294}
295295
296+ impl < ' a > ClientOptions < ' a > {
297+ /// Initialize a new [`ClientOptions`] with default settings.
298+ pub fn new ( service_name : & ' a str ) -> Self {
299+ Self { service_name, qos : QoSProfile :: services_default ( ) }
300+ }
301+ }
302+
296303impl < ' a , T : IntoPrimitiveOptions < ' a > > From < T > for ClientOptions < ' a > {
297304 fn from ( value : T ) -> Self {
298- let options = value. into_primitive_options ( ) ;
299- let mut qos = QoSProfile :: services_default ( ) ;
300- options . apply ( & mut qos) ;
301- Self { service_name : options. name , qos }
305+ let primitive = value. into_primitive_options ( ) ;
306+ let mut options = Self :: new ( primitive . name ) ;
307+ primitive . apply ( & mut options . qos ) ;
308+ options
302309 }
303310}
304311
Original file line number Diff line number Diff line change @@ -244,12 +244,19 @@ pub struct PublisherOptions<'a> {
244244 pub qos : QoSProfile ,
245245}
246246
247+ impl < ' a > PublisherOptions < ' a > {
248+ /// Initialize a new [`PublisherOptions`] with default settings.
249+ pub fn new ( topic : & ' a str ) -> Self {
250+ Self { topic, qos : QoSProfile :: topics_default ( ) }
251+ }
252+ }
253+
247254impl < ' a , T : IntoPrimitiveOptions < ' a > > From < T > for PublisherOptions < ' a > {
248255 fn from ( value : T ) -> Self {
249- let options = value. into_primitive_options ( ) ;
250- let mut qos = QoSProfile :: topics_default ( ) ;
251- options . apply ( & mut qos) ;
252- Self { topic : options. name , qos }
256+ let primitive = value. into_primitive_options ( ) ;
257+ let mut options = Self :: new ( primitive . name ) ;
258+ primitive . apply ( & mut options . qos ) ;
259+ options
253260 }
254261}
255262
Original file line number Diff line number Diff line change @@ -192,16 +192,23 @@ where
192192pub struct ServiceOptions < ' a > {
193193 /// The name for the service
194194 pub name : & ' a str ,
195- /// The quality of service for the service.
195+ /// The quality of service profile for the service.
196196 pub qos : QoSProfile ,
197197}
198198
199+ impl < ' a > ServiceOptions < ' a > {
200+ /// Initialize a new [`ServiceOptions`] with default settings.
201+ pub fn new ( name : & ' a str ) -> Self {
202+ Self { name, qos : QoSProfile :: services_default ( ) }
203+ }
204+ }
205+
199206impl < ' a , T : IntoPrimitiveOptions < ' a > > From < T > for ServiceOptions < ' a > {
200207 fn from ( value : T ) -> Self {
201- let options = value. into_primitive_options ( ) ;
202- let mut qos = QoSProfile :: services_default ( ) ;
203- options . apply ( & mut qos) ;
204- Self { name : options. name , qos }
208+ let primitive = value. into_primitive_options ( ) ;
209+ let mut options = Self :: new ( primitive . name ) ;
210+ primitive . apply ( & mut options . qos ) ;
211+ options
205212 }
206213}
207214
Original file line number Diff line number Diff line change @@ -276,14 +276,19 @@ pub struct SubscriptionOptions<'a> {
276276 pub qos : QoSProfile ,
277277}
278278
279+ impl < ' a > SubscriptionOptions < ' a > {
280+ /// Initialize a new [`SubscriptionOptions`] with default settings.
281+ pub fn new ( topic : & ' a str ) -> Self {
282+ Self { topic, qos : QoSProfile :: topics_default ( ) }
283+ }
284+ }
285+
279286impl < ' a , T : IntoPrimitiveOptions < ' a > > From < T > for SubscriptionOptions < ' a > {
280287 fn from ( value : T ) -> Self {
281- let options = value. into_primitive_options ( ) ;
282- // Topics will use the QOS_PROFILE_DEFAULT by default, which is designed
283- // to roughly match the ROS 1 default topic behavior.
284- let mut qos = QoSProfile :: topics_default ( ) ;
285- options. apply ( & mut qos) ;
286- Self { topic : options. name , qos }
288+ let primitive = value. into_primitive_options ( ) ;
289+ let mut options = Self :: new ( primitive. name ) ;
290+ primitive. apply ( & mut options. qos ) ;
291+ options
287292 }
288293}
289294
You can’t perform that action at this time.
0 commit comments