summaryrefslogtreecommitdiffstats
path: root/third_party/rust/pulse/src/proplist.rs
blob: 460473f4677d276761b27022d40f8b3685e5176f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright © 2017 Mozilla Foundation
//
// This program is made available under an ISC-style license.  See the
// accompanying file LICENSE for details.

use ffi;
use std::ffi::{CStr, CString};

#[derive(Debug)]
pub struct Proplist(*mut ffi::pa_proplist);

impl Proplist {
    pub fn gets<T>(&self, key: T) -> Option<&CStr>
    where
        T: Into<Vec<u8>>,
    {
        let key = match CString::new(key) {
            Ok(k) => k,
            _ => return None,
        };
        let r = unsafe { ffi::pa_proplist_gets(self.0, key.as_ptr()) };
        if r.is_null() {
            None
        } else {
            Some(unsafe { CStr::from_ptr(r) })
        }
    }
}

pub unsafe fn from_raw_ptr(raw: *mut ffi::pa_proplist) -> Proplist {
    return Proplist(raw);
}