-
Having problem with sending a Vector of a struct. Getting the following error. Any help? Error:
Request: Return Payload:
Struct Implementation: #[derive(Debug, Clone)]
pub struct AppInfo {
pub total_score: f64,
pub name: String,
pub exec: String,
pub icon: String,
}
impl Arg for AppInfo {
const ARG_TYPE: ArgType = ArgType::Struct;
fn signature() -> Signature<'static> {
Signature::new("(dsss)").unwrap()
}
}
impl Append for AppInfo {
fn append_by_ref(&self, ia: &mut IterAppend){
self.total_score.append(ia);
self.name.as_str().append(ia);
self.exec.as_str().append(ia);
self.icon.as_str().append(ia);
}
} Method Implementation: builder.method("get_result", ("query",), ("config",), move |_, _, (query,): (String,)| {
let mut result = Vec::new();
result.push(AppInfo {
total_score: 0.1,
name: String::from("FakeApp"),
icon: String::from("other"),
exec: String::from("fake")
});
result.push(AppInfo {
total_score: 0.1,
name: String::from("FakeApp"),
icon: String::from("other"),
exec: String::from("fake")
});
println!("{}", Vec::<AppInfo>::signature());
Ok((result,))
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@mdgaziur Before I get started, I'ld like to mention that I am not @diwic, and so much more likely to be wrong. However, as far as I can tell the problem that you are encountering is due to the fact that you have implemented Append for your
I feel fairly confident that my suggestion won't compile, but it should do the correct thing once that is fixed. |
Beta Was this translation helpful? Give feedback.
@mdgaziur Before I get started, I'ld like to mention that I am not @diwic, and so much more likely to be wrong. However, as far as I can tell the problem that you are encountering is due to the fact that you have implemented Append for your
AppInfo
type incorrectly. Your Append implementation just destructures the struct into its individual parts. In the D-Bus spec, a "struct" is just a tuple. You need to hand it in the proper form to the append function. Something similar to this is likely to work better.I feel fairly confident that…