dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

bincode fails to serialize structs implementing zvariant::SerializeDict #284

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @hojjatabdollahi on Aug 12, 2022, 21:45

The bincode can serialize structs implementing serde::Serialize but not zvariant::Serialize. See this example:

use serde::Serialize;
use zbus::zvariant::SerializeDict;

#[derive(Serialize)]
struct S1 {
    f1: u32,
}

#[derive(SerializeDict)]
struct S2 {
    f1: u32,
}

fn main() {
    let s1 = S1 { f1: 3 };
    let s2 = S2 { f1: 3 };
    bincode::serialize(&s1).unwrap(); // <- Works fine
    bincode::serialize(&s2).unwrap(); // <- Error
}

This fails with: thread 'main' panicked at 'called Result::unwrap() on an Err value: SequenceMustHaveLength', src/main.rs:17:29

zeenix commented 2 years ago

@hojjatabdollahi Thanks for filing this. As I expected, the fix was trivial.