Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions commons/zenoh-protocol/src/core/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ pub fn values<'s>(s: &'s str, k: &str) -> impl DoubleEndedIterator<Item = &'s st
match get(s, k) {
Some(v) => v.split(VALUE_SEPARATOR),
None => {
// Create an empty iterator of the same type as the `Some` case to make the compiler happy.
let mut i = "".split(VALUE_SEPARATOR);
// Need to skip the first element, as splitting `""` by `"|"` returns `vec![""]`.
i.next();
i
}
Expand Down Expand Up @@ -214,9 +216,11 @@ pub fn rand(into: &mut String) {
}
}

/// A map of key/value (String,String) parameters.
/// It can be parsed from a String, using `;` or `<newline>` as separator between each parameters
/// and `=` as separator between a key and its value. Keys and values are trimmed.
/// A map of key/value `(String, Vec<String>)` parameters.
///
/// It can be parsed from a `String`, using `;` as separator between each parameter and `=` as separator between a key and its value.
///
/// Keys can have multiple values, using `|` as a separator between them. An iterator for these can be obtained with [`Parameters::values`].
///
/// Example:
/// ```
Expand Down Expand Up @@ -294,7 +298,7 @@ impl<'s> Parameters<'s> {
}

/// Inserts a key-value pair into the map.
/// If the map did not have this key present, [`None`]` is returned.
/// If the map did not have this key present, [`None`] is returned.
/// If the map did have this key present, the value is updated, and the old value is returned.
pub fn insert<K, V>(&mut self, k: K, v: V) -> Option<String>
where
Expand Down Expand Up @@ -342,7 +346,7 @@ impl<'s> Parameters<'s> {
Parameters(Cow::Owned(self.0.into_owned()))
}

/// Returns `true`` if all keys are sorted in alphabetical order.
/// Returns `true` if all keys are sorted in alphabetical order.
pub fn is_ordered(&self) -> bool {
super::parameters::is_ordered(self.as_str())
}
Expand Down Expand Up @@ -523,4 +527,11 @@ mod tests {
hm.insert(Cow::from("p1"), Cow::from("v1"));
assert_eq!(Parameters::from(hm), Parameters::from("p1=v1"));
}

#[test]
fn values_iterator_for_non_existing_key_is_empty() {
let params = Parameters::from("p1=1");

assert_eq!(params.values("p2").next(), None);
}
}
Loading