Parameters

Struct Parameters 

Source
pub struct Parameters<'s>(/* private fields */);
Expand description

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.

Example:

use zenoh_protocol::core::Parameters;

let a = "a=1;b=2;c=3|4|5;d=6";
let p = Parameters::from(a);

// Retrieve values
assert!(!p.is_empty());
assert_eq!(p.get("a").unwrap(), "1");
assert_eq!(p.get("b").unwrap(), "2");
assert_eq!(p.get("c").unwrap(), "3|4|5");
assert_eq!(p.get("d").unwrap(), "6");
assert_eq!(p.values("c").collect::<Vec<&str>>(), vec!["3", "4", "5"]);

// Iterate over parameters
let mut iter = p.iter();
assert_eq!(iter.next().unwrap(), ("a", "1"));
assert_eq!(iter.next().unwrap(), ("b", "2"));
assert_eq!(iter.next().unwrap(), ("c", "3|4|5"));
assert_eq!(iter.next().unwrap(), ("d", "6"));
assert!(iter.next().is_none());

// Create parameters from iterators
let pi = Parameters::from_iter(vec![("a", "1"), ("b", "2"), ("c", "3|4|5"), ("d", "6")]);
assert_eq!(p, pi);

Implementations§

Source§

impl<'s> Parameters<'s>

Source

pub const fn empty() -> Self

Create empty parameters.

Source

pub fn is_empty(&self) -> bool

Returns true if parameters does not contain anything.

Source

pub fn as_str(&'s self) -> &'s str

Returns parameters as str.

Source

pub fn contains_key<K>(&self, k: K) -> bool
where K: Borrow<str>,

Returns true if parameters contains the specified key.

Source

pub fn get<K>(&'s self, k: K) -> Option<&'s str>
where K: Borrow<str>,

Returns a reference to the &str-value corresponding to the key.

Source

pub fn values<K>(&'s self, k: K) -> impl DoubleEndedIterator<Item = &'s str>
where K: Borrow<str>,

Returns an iterator to the &str-values corresponding to the key.

Source

pub fn iter( &'s self, ) -> impl DoubleEndedIterator<Item = (&'s str, &'s str)> + Clone

Returns an iterator on the key-value pairs as (&str, &str).

Source

pub fn insert<K, V>(&mut self, k: K, v: V) -> Option<String>
where K: Borrow<str>, V: Borrow<str>,

Inserts a key-value pair into the map. 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.

Source

pub fn remove<K>(&mut self, k: K) -> Option<String>
where K: Borrow<str>,

Removes a key from the map, returning the value at the key if the key was previously in the parameters.

Source

pub fn extend(&mut self, other: &Parameters<'_>)

Extend these parameters with other parameters.

Source

pub fn extend_from_iter<'e, I, K, V>(&mut self, iter: I)
where I: Iterator<Item = (&'e K, &'e V)> + Clone, K: Borrow<str> + 'e + ?Sized, V: Borrow<str> + 'e + ?Sized,

Extend these parameters from an iterator.

Source

pub fn into_owned(self) -> Parameters<'static>

Convert these parameters into owned parameters.

Source

pub fn is_ordered(&self) -> bool

Returns `true`` if all keys are sorted in alphabetical order.

Trait Implementations§

Source§

impl<'s> Clone for Parameters<'s>

Source§

fn clone(&self) -> Parameters<'s>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Parameters<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> Default for Parameters<'s>

Source§

fn default() -> Parameters<'s>

Returns the “default value” for a type. Read more
Source§

impl Display for Parameters<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s, K, V> From<&'s [(K, V)]> for Parameters<'_>
where K: Borrow<str> + 's, V: Borrow<str> + 's,

Source§

fn from(value: &'s [(K, V)]) -> Self

Converts to this type from the input type.
Source§

impl From<&Parameters<'_>> for HashMap<String, String>

Source§

fn from(props: &Parameters<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Parameters<'a>> for Cow<'a, Parameters<'a>>

Source§

fn from(props: &'a Parameters<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s Parameters<'s>> for HashMap<&'s str, &'s str>

Source§

fn from(props: &'s Parameters<'s>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s Parameters<'s>> for HashMap<Cow<'s, str>, Cow<'s, str>>

Source§

fn from(props: &'s Parameters<'s>) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<&'s str> for Parameters<'s>

Source§

fn from(value: &'s str) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<Cow<'s, str>> for Parameters<'s>

Source§

fn from(value: Cow<'s, str>) -> Self

Converts to this type from the input type.
Source§

impl<K, V> From<HashMap<K, V>> for Parameters<'_>
where K: Borrow<str>, V: Borrow<str>,

Source§

fn from(map: HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl From<Parameters<'_>> for HashMap<String, String>

Source§

fn from(props: Parameters<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Parameters<'a>> for Cow<'_, Parameters<'a>>

Source§

fn from(props: Parameters<'a>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Parameters<'_>

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<'s, K, V> FromIterator<&'s (K, V)> for Parameters<'_>
where K: Borrow<str> + 's, V: Borrow<str> + 's,

Source§

fn from_iter<T: IntoIterator<Item = &'s (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'s, K, V> FromIterator<(&'s K, &'s V)> for Parameters<'_>
where K: Borrow<str> + 's + ?Sized, V: Borrow<str> + 's + ?Sized,

Source§

fn from_iter<T: IntoIterator<Item = (&'s K, &'s V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'s> Hash for Parameters<'s>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'s> PartialEq for Parameters<'s>

Source§

fn eq(&self, other: &Parameters<'s>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'s> Eq for Parameters<'s>

Source§

impl<'s> StructuralPartialEq for Parameters<'s>

Auto Trait Implementations§

§

impl<'s> Freeze for Parameters<'s>

§

impl<'s> RefUnwindSafe for Parameters<'s>

§

impl<'s> Send for Parameters<'s>

§

impl<'s> Sync for Parameters<'s>

§

impl<'s> Unpin for Parameters<'s>

§

impl<'s> UnwindSafe for Parameters<'s>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsNode<T> for T

Source§

fn as_node(&self) -> &T

Source§

impl<T> AsNodeMut<T> for T

Source§

fn as_node_mut(&mut self) -> &mut T

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V