From 340f38f374c81fe9f64e7bc1bab824940d0c09f3 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Wed, 27 Nov 2024 11:53:27 +0100 Subject: [PATCH 1/3] Fix invalid warning when is not defined --- zenoh-plugin-ros2dds/src/config.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/zenoh-plugin-ros2dds/src/config.rs b/zenoh-plugin-ros2dds/src/config.rs index 0579aba..ca1c0d5 100644 --- a/zenoh-plugin-ros2dds/src/config.rs +++ b/zenoh-plugin-ros2dds/src/config.rs @@ -15,6 +15,7 @@ use std::{env, fmt, time::Duration}; use regex::Regex; use serde::{de, de::Visitor, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; +use tracing::warn; use zenoh::{key_expr::OwnedKeyExpr, qos::Priority}; pub const DEFAULT_NAMESPACE: &str = "/"; @@ -486,12 +487,17 @@ fn default_localhost_only() -> bool { } fn default_automatic_discovery_range() -> Option { - Some(match env::var("ROS_AUTOMATIC_DISCOVERY_RANGE").as_deref() { - Ok("LOCALHOST") => RosAutomaticDiscoveryRange::Localhost, - Ok("OFF") => RosAutomaticDiscoveryRange::Localhost, - Ok("SYSTEM_DEFAULT") => RosAutomaticDiscoveryRange::SystemDefault, - _ => RosAutomaticDiscoveryRange::Subnet, - }) + match env::var("ROS_AUTOMATIC_DISCOVERY_RANGE").as_deref() { + Ok("SUBNET") => Some(RosAutomaticDiscoveryRange::Subnet), + Ok("LOCALHOST") => Some(RosAutomaticDiscoveryRange::Localhost), + Ok("OFF") => Some(RosAutomaticDiscoveryRange::Localhost), + Ok("SYSTEM_DEFAULT") => Some(RosAutomaticDiscoveryRange::SystemDefault), + Ok(value) => { + warn!(r#"Invalid value for environment variable ROS_AUTOMATIC_DISCOVERY_RANGE ("{value}"). Using "SUBNET" instead "#); + Some(RosAutomaticDiscoveryRange::Subnet) + } + Err(_) => None, + } } fn deserialize_automatic_discovery_range<'de, D>( @@ -507,7 +513,7 @@ where "OFF" => Ok(Some(RosAutomaticDiscoveryRange::Off)), "SYSTEM_DEFAULT" => Ok(Some(RosAutomaticDiscoveryRange::SystemDefault)), unknown => Err(de::Error::custom(format!( - r#"Invalid parameter {unknown} for ROS_AUTOMATICALLY_DISCOVERY_RANGE"# + r#"Invalid parameter "{unknown}" for ROS_AUTOMATICALLY_DISCOVERY_RANGE"# ))), } } From 7ce4c9198f5736818c4129090e14666fa3abdce8 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Wed, 27 Nov 2024 12:02:23 +0100 Subject: [PATCH 2/3] fix format and clippy warns --- zenoh-plugin-ros2dds/src/config.rs | 6 ++++-- zenoh-plugin-ros2dds/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/zenoh-plugin-ros2dds/src/config.rs b/zenoh-plugin-ros2dds/src/config.rs index ca1c0d5..55f525a 100644 --- a/zenoh-plugin-ros2dds/src/config.rs +++ b/zenoh-plugin-ros2dds/src/config.rs @@ -493,7 +493,9 @@ fn default_automatic_discovery_range() -> Option { Ok("OFF") => Some(RosAutomaticDiscoveryRange::Localhost), Ok("SYSTEM_DEFAULT") => Some(RosAutomaticDiscoveryRange::SystemDefault), Ok(value) => { - warn!(r#"Invalid value for environment variable ROS_AUTOMATIC_DISCOVERY_RANGE ("{value}"). Using "SUBNET" instead "#); + warn!( + r#"Invalid value for environment variable ROS_AUTOMATIC_DISCOVERY_RANGE ("{value}"). Using "SUBNET" instead "# + ); Some(RosAutomaticDiscoveryRange::Subnet) } Err(_) => None, @@ -525,7 +527,7 @@ where let peers: String = Deserialize::deserialize(deserializer).unwrap(); let mut peer_list: Vec = Vec::new(); for peer in peers.split(';') { - if peer != "" { + if !peer.is_empty() { peer_list.push(peer.to_owned()); } } diff --git a/zenoh-plugin-ros2dds/src/lib.rs b/zenoh-plugin-ros2dds/src/lib.rs index d72208f..ff5e727 100644 --- a/zenoh-plugin-ros2dds/src/lib.rs +++ b/zenoh-plugin-ros2dds/src/lib.rs @@ -331,7 +331,7 @@ pub async fn run(runtime: Runtime, config: Config) { (Some(RosAutomaticDiscoveryRange::Localhost), None) } else { ( - config.ros_automatic_discovery_range.clone(), + config.ros_automatic_discovery_range, config.ros_static_peers.clone(), ) }; From 3b3f58f406a765b0109ce7cc1699f4c54a1c85ee Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Wed, 27 Nov 2024 13:56:20 +0100 Subject: [PATCH 3/3] Fix unit test --- zenoh-plugin-ros2dds/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zenoh-plugin-ros2dds/src/config.rs b/zenoh-plugin-ros2dds/src/config.rs index 55f525a..b1eb7a5 100644 --- a/zenoh-plugin-ros2dds/src/config.rs +++ b/zenoh-plugin-ros2dds/src/config.rs @@ -933,7 +933,7 @@ mod tests { assert_eq!(__required__, None); } - #[test_case("{}", Some(RosAutomaticDiscoveryRange::Subnet); "Empty tests")] + #[test_case("{}", None; "Empty tests")] #[test_case(r#"{"ros_automatic_discovery_range": "SUBNET"}"#, Some(RosAutomaticDiscoveryRange::Subnet); "SUBNET tests")] #[test_case(r#"{"ros_automatic_discovery_range": "LOCALHOST"}"#, Some(RosAutomaticDiscoveryRange::Localhost); "LOCALHOST tests")] #[test_case(r#"{"ros_automatic_discovery_range": "OFF"}"#, Some(RosAutomaticDiscoveryRange::Off); "OFF tests")]