cargo fmt
This commit is contained in:
@@ -5,19 +5,27 @@ use xpc_connection::Message;
|
||||
|
||||
pub type XpcMap = HashMap<CString, Message>;
|
||||
|
||||
pub fn cstr(s: &str) -> CString { CString::new(s).unwrap_or_else(|_| CString::new("").unwrap()) }
|
||||
pub fn cstr(s: &str) -> CString {
|
||||
CString::new(s).unwrap_or_else(|_| CString::new("").unwrap())
|
||||
}
|
||||
|
||||
pub fn get_dictionary_field<'a>(
|
||||
map: &'a HashMap<CString, Message>,
|
||||
key: &str,
|
||||
) -> Option<&'a HashMap<CString, Message>> {
|
||||
let k = CString::new(key).ok()?;
|
||||
map.get(&k).and_then(|v| match v { Message::Dictionary(d) => Some(d), _ => None })
|
||||
map.get(&k).and_then(|v| match v {
|
||||
Message::Dictionary(d) => Some(d),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn dict_get_str(map: &HashMap<CString, Message>, key: &str) -> Option<String> {
|
||||
let k = CString::new(key).ok()?;
|
||||
match map.get(&k) { Some(Message::String(v)) => Some(v.to_string_lossy().into_owned()), _ => None }
|
||||
match map.get(&k) {
|
||||
Some(Message::String(v)) => Some(v.to_string_lossy().into_owned()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dict_get_i64_from_str(map: &HashMap<CString, Message>, key: &str) -> Option<i64> {
|
||||
@@ -28,10 +36,15 @@ pub fn dict_put_str(map: &mut XpcMap, key: &str, value: impl AsRef<str>) {
|
||||
map.insert(cstr(key), Message::String(cstr(value.as_ref())));
|
||||
}
|
||||
|
||||
pub fn dict_put_i64_as_str(map: &mut XpcMap, key: &str, value: i64) { dict_put_str(map, key, value.to_string()); }
|
||||
pub fn dict_put_i64_as_str(map: &mut XpcMap, key: &str, value: i64) {
|
||||
dict_put_str(map, key, value.to_string());
|
||||
}
|
||||
|
||||
pub fn array_from_strs(values: impl IntoIterator<Item = String>) -> Message {
|
||||
let arr = values.into_iter().map(|s| Message::String(cstr(&s))).collect();
|
||||
let arr = values
|
||||
.into_iter()
|
||||
.map(|s| Message::String(cstr(&s)))
|
||||
.collect();
|
||||
Message::Array(arr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user