Struct libspa::utils::dict::DictRef

source ·
pub struct DictRef(/* private fields */);

Implementations§

source§

impl DictRef

source

pub fn as_raw(&self) -> &spa_dict

Returns a reference to the raw spa_sys::spa_dict this struct represents.

source

pub fn as_raw_ptr(&self) -> *mut spa_dict

Returns the pointer to the raw spa_sys::spa_dict this struct represents.

§Safety

The returned pointer must not be used after the DictRef reference this method is called on becomes invalid.

source

pub fn iter_cstr(&self) -> CIter<'_>

An iterator over all key-value pairs as (&CStr, &CStr) tuples.

Use iter to iterate over all valid utf-8 pairs as (&str, &str) tuples instead.

source

pub fn iter(&self) -> Iter<'_>

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

source

pub fn keys(&self) -> Keys<'_>

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

source

pub fn values(&self) -> Values<'_>

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

source

pub 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.

source

pub fn is_empty(&self) -> bool

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

source

pub fn flags(&self) -> Flags

Returns the bitflags that are set for the dict.

source

pub 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.

source

pub fn parse<T: ParsableValue>( &self, key: &str ) -> Option<Result<T, ParseValueError>>

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::{utils::dict::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());

Trait Implementations§

source§

impl AsRef<DictRef> for DictRef

source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Debug for DictRef

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.