Trait pipewire::prelude::ReadableDict[][src]

pub trait ReadableDict {
    fn get_dict_ptr(&self) -> *const spa_dict;

    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

Obtain the pointer to the raw spa_dict struct.

Provided methods

An iterator over all raw key-value pairs. The iterator element type is (&CStr, &CStr).

An iterator over all key-value pairs that are valid utf-8. The iterator element type is (&str, &str).

An iterator over all keys that are valid utf-8. The iterator element type is &str.

An iterator over all values that are valid utf-8. The iterator element type is &str.

Returns the number of key-value-pairs in the dict. This is the number of all pairs, not only pairs that are valid-utf8.

Returns true if the dict is empty, false if it is not.

Returns the bitflags that are set for the dict.

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.

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());

Implementations on Foreign Types

Implementors