diff --git a/rclrs/src/client.rs b/rclrs/src/client.rs index 428a0245f..05282c35c 100644 --- a/rclrs/src/client.rs +++ b/rclrs/src/client.rs @@ -294,18 +294,25 @@ pub struct ClientOptions<'a> { pub qos: QoSProfile, } -impl<'a, T: IntoPrimitiveOptions<'a>> From for ClientOptions<'a> { - fn from(value: T) -> Self { - let options = value.into_primitive_options(); - let mut qos = QoSProfile::services_default(); - options.apply(&mut qos); +impl<'a> ClientOptions<'a> { + /// Initialize a new [`ClientOptions`] with default settings. + pub fn new(service_name: &'a str) -> Self { Self { - service_name: options.name, - qos, + service_name, + qos: QoSProfile::services_default(), } } } +impl<'a, T: IntoPrimitiveOptions<'a>> From for ClientOptions<'a> { + fn from(value: T) -> Self { + let primitive = value.into_primitive_options(); + let mut options = Self::new(primitive.name); + primitive.apply(&mut options.qos); + options + } +} + impl ClientBase for Client where T: rosidl_runtime_rs::Service, diff --git a/rclrs/src/publisher.rs b/rclrs/src/publisher.rs index c37c446e0..bc299f14e 100644 --- a/rclrs/src/publisher.rs +++ b/rclrs/src/publisher.rs @@ -244,18 +244,25 @@ pub struct PublisherOptions<'a> { pub qos: QoSProfile, } -impl<'a, T: IntoPrimitiveOptions<'a>> From for PublisherOptions<'a> { - fn from(value: T) -> Self { - let options = value.into_primitive_options(); - let mut qos = QoSProfile::topics_default(); - options.apply(&mut qos); +impl<'a> PublisherOptions<'a> { + /// Initialize a new [`PublisherOptions`] with default settings. + pub fn new(topic: &'a str) -> Self { Self { - topic: options.name, - qos, + topic, + qos: QoSProfile::topics_default(), } } } +impl<'a, T: IntoPrimitiveOptions<'a>> From for PublisherOptions<'a> { + fn from(value: T) -> Self { + let primitive = value.into_primitive_options(); + let mut options = Self::new(primitive.name); + primitive.apply(&mut options.qos); + options + } +} + /// Convenience trait for [`Publisher::publish`]. pub trait MessageCow<'a, T: Message> { /// Wrap the owned or borrowed message in a `Cow`. diff --git a/rclrs/src/service.rs b/rclrs/src/service.rs index eb810ad1a..1ff18c5b3 100644 --- a/rclrs/src/service.rs +++ b/rclrs/src/service.rs @@ -190,22 +190,29 @@ where pub struct ServiceOptions<'a> { /// The name for the service pub name: &'a str, - /// The quality of service for the service. + /// The quality of service profile for the service. pub qos: QoSProfile, } -impl<'a, T: IntoPrimitiveOptions<'a>> From for ServiceOptions<'a> { - fn from(value: T) -> Self { - let options = value.into_primitive_options(); - let mut qos = QoSProfile::services_default(); - options.apply(&mut qos); +impl<'a> ServiceOptions<'a> { + /// Initialize a new [`ServiceOptions`] with default settings. + pub fn new(name: &'a str) -> Self { Self { - name: options.name, - qos, + name, + qos: QoSProfile::services_default(), } } } +impl<'a, T: IntoPrimitiveOptions<'a>> From for ServiceOptions<'a> { + fn from(value: T) -> Self { + let primitive = value.into_primitive_options(); + let mut options = Self::new(primitive.name); + primitive.apply(&mut options.qos); + options + } +} + impl ServiceBase for Service where T: rosidl_runtime_rs::Service, diff --git a/rclrs/src/subscription.rs b/rclrs/src/subscription.rs index 0494f71c9..cfc77cfc5 100644 --- a/rclrs/src/subscription.rs +++ b/rclrs/src/subscription.rs @@ -274,20 +274,25 @@ pub struct SubscriptionOptions<'a> { pub qos: QoSProfile, } -impl<'a, T: IntoPrimitiveOptions<'a>> From for SubscriptionOptions<'a> { - fn from(value: T) -> Self { - let options = value.into_primitive_options(); - // Topics will use the QOS_PROFILE_DEFAULT by default, which is designed - // to roughly match the ROS 1 default topic behavior. - let mut qos = QoSProfile::topics_default(); - options.apply(&mut qos); +impl<'a> SubscriptionOptions<'a> { + /// Initialize a new [`SubscriptionOptions`] with default settings. + pub fn new(topic: &'a str) -> Self { Self { - topic: options.name, - qos, + topic, + qos: QoSProfile::topics_default(), } } } +impl<'a, T: IntoPrimitiveOptions<'a>> From for SubscriptionOptions<'a> { + fn from(value: T) -> Self { + let primitive = value.into_primitive_options(); + let mut options = Self::new(primitive.name); + primitive.apply(&mut options.qos); + options + } +} + impl SubscriptionBase for Subscription where T: Message,