Function zbus_lockstep::get_method_args_type
source · pub fn get_method_args_type<'a>(
xml: impl Read,
interface_name: &str,
member_name: &str,
arg_name: Option<&str>
) -> Result<Signature<'a>, Box<dyn Error>>
Expand description
Retrieve the signature of a method’s argument type from XML.
Useful when one or more arguments, used to call a method, outline a useful type.
If you provide an argument name, then the signature of that argument is returned. If you do not provide an argument name, then the signature of all arguments to the call is returned.
§Examples
use std::fs::File;
use std::collections::HashMap;
use std::io::{Seek, SeekFrom, Write};
use tempfile::tempfile;
use zvariant::{Type, Value};
use zbus_lockstep::get_method_args_type;
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="org.freedesktop.Notifications">
<method name="Notify">
<arg type="s" name="app_name" direction="in"/>
<arg type="u" name="replaces_id" direction="in"/>
<arg type="s" name="app_icon" direction="in"/>
<arg type="s" name="summary" direction="in"/>
<arg type="s" name="body" direction="in"/>
<arg type="as" name="actions" direction="in"/>
<arg type="a{sv}" name="hints" direction="in"/>
<arg type="i" name="expire_timeout" direction="in"/>
<arg type="u" name="id" direction="out"/>
</method>
</interface>
</node>
"#;
#[derive(Debug, PartialEq, Type)]
struct Notification<'a> {
app_name: String,
replaces_id: u32,
app_icon: String,
summary: String,
body: String,
actions: Vec<String>,
hints: HashMap<String, Value<'a>>,
expire_timeout: i32,
}
let mut xml_file = tempfile().unwrap();
xml_file.write_all(xml.as_bytes()).unwrap();
xml_file.seek(SeekFrom::Start(0)).unwrap();
let interface_name = "org.freedesktop.Notifications";
let member_name = "Notify";
let signature = get_method_args_type(xml_file, interface_name, member_name, None).unwrap();
assert_eq!(&signature, &Notification::signature());