It is not clear to me how to serialize structs as parameters to request. In particular I seem to be missing a step to convert the struct to a BTreeMap
which then in turn can be used as a Value
.
use serde::Serialize;
use serde_xmlrpc::{request_to_string, Value};
fn main() {
let param = Custom {
field: 42
};
let request = request_to_string("example", vec![
Value::from(param) // Error (see below)
]).unwrap();
}
#[derive(Serialize)]
struct Custom {
field: i32,
}
error[E0277]: the trait bound `Value: From<Custom>` is not satisfied
--> src/bin/serde-xmlrpc-structs-as-value.rs:10:9
|
10 | Value::from(param)
| ^^^^^^^^^^^ the trait `From<Custom>` is not implemented for `Value`
|
= help: the following implementations were found:
<Value as From<&str>>
<Value as From<BTreeMap<std::string::String, Value>>>
<Value as From<Vec<Value>>>
<Value as From<Vec<u8>>>
and 6 others
= note: required by `std::convert::From::from`
Whereas the "opposite" operation, de-serializing the struct from a response works just fine:
use serde::Deserialize;
use serde_xmlrpc::response_from_str;
fn main() {
let resp: Custom = response_from_str(
"<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>field</name>
<value><int>42</int></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>").unwrap();
println!("{:?}", resp);
}
#[derive(Deserialize, Debug)]
struct Custom {
field: i32,
}
I might be just missing something obvious here. Is there any way I can serialize a struct as a Value/parameter in a request?