Debian Codegraph @

third_party/rust/pulse/src/proplist.rs

raw
1 // Copyright © 2017 Mozilla Foundation
2 //
3 // This program is made available under an ISC-style license. See the
4 // accompanying file LICENSE for details.
5
6 use ffi;
7 use std::ffi::{CStr, CString};
8
9 #[derive(Debug)]
10 pub struct Proplist(*mut ffi::pa_proplist);
11
12 impl Proplist {
13 pub fn gets<T>(&self, key: T) -> Option<&CStr>
14 where
15 T: Into<Vec<u8>>,
16 {
17 let key = match CString::new(key) {
18 Ok(k) => k,
19 _ => return None,
20 };
21 let r = unsafe { ffi::pa_proplist_gets(self.0, key.as_ptr()) };
22 if r.is_null() {
23 None
24 } else {
25 Some(unsafe { CStr::from_ptr(r) })
26 }
27 }
28 }
29
30 pub unsafe fn from_raw_ptr(raw: *mut ffi::pa_proplist) -> Proplist {
31 return Proplist(raw);
32 }