Trait pipewire::prelude::ReadableDict
source · pub trait ReadableDict {
// Required method
fn get_dict_ptr(&self) -> *const spa_dict;
// Provided methods
fn iter_cstr(&self) -> CIter<'_> { ... }
fn iter(&self) -> Iter<'_> { ... }
fn keys(&self) -> Keys<'_> { ... }
fn values(&self) -> Values<'_> { ... }
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn flags(&self) -> Flags { ... }
fn get(&self, key: &str) -> Option<&str> { ... }
fn parse<T>(&self, key: &str) -> Option<Result<T, ParseValueError>>
where T: ParsableValue { ... }
}
Expand description
Trait providing API to read dictionaries.
Required Methods§
sourcefn get_dict_ptr(&self) -> *const spa_dict
fn get_dict_ptr(&self) -> *const spa_dict
Obtain the pointer to the raw spa_dict
struct.
Provided Methods§
sourcefn iter_cstr(&self) -> CIter<'_>
fn iter_cstr(&self) -> CIter<'_>
An iterator over all raw key-value pairs.
The iterator element type is (&CStr, &CStr)
.
sourcefn iter(&self) -> Iter<'_>
fn iter(&self) -> Iter<'_>
An iterator over all key-value pairs that are valid utf-8.
The iterator element type is (&str, &str)
.
sourcefn keys(&self) -> Keys<'_>
fn keys(&self) -> Keys<'_>
An iterator over all keys that are valid utf-8. The iterator element type is &str.
sourcefn values(&self) -> Values<'_>
fn values(&self) -> Values<'_>
An iterator over all values that are valid utf-8. The iterator element type is &str.
sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of key-value-pairs in the dict. This is the number of all pairs, not only pairs that are valid-utf8.
sourcefn get(&self, key: &str) -> Option<&str>
fn get(&self, key: &str) -> Option<&str>
Get the value associated with the provided key.
If the dict does not contain the key or the value is non-utf8, None
is returned.
Use iter_cstr
if you need a non-utf8 key or value.
sourcefn parse<T>(&self, key: &str) -> Option<Result<T, ParseValueError>>where
T: ParsableValue,
fn parse<T>(&self, key: &str) -> Option<Result<T, ParseValueError>>where T: ParsableValue,
Get the value associated with the provided key and convert it to a given type.
If the dict does not contain the key or the value is non-utf8, None
is returned.
If the value associated with the key cannot be parsed to the requested type,
Some(Err(ParseValueError))
is returned.
See ParsableValue
for all the types which can be produced by this method.
Examples
use libspa::prelude::*;
use libspa::{StaticDict, static_dict};
static DICT: StaticDict = static_dict! {
"true" => "true",
"ten" => "10",
"pi" => "3.14159265359",
"pointer" => "pointer:0xdeadbeef"
};
assert_eq!(DICT.parse("true"), Some(Ok(true)));
assert_eq!(DICT.parse("ten"), Some(Ok(10)));
assert_eq!(DICT.parse("ten"), Some(Ok(10.0)));
assert_eq!(DICT.parse("pi"), Some(Ok(3.14159265359)));
let ptr = DICT.parse::<*const i32>("pointer").unwrap().unwrap();
assert!(!ptr.is_null());