zvariant: Struct without fields produce type signature "()" which fails parsing
Hi!
It's my first issue here, so let me start by saying thank you for your work and provided code & documentation! I have only played around with it for a few hours but I am quite pleased with it.
So, I stumbled over a corner case that seems like a bug.
Structs without fields (for example struct EmptyStruct {}
) can derive zvariant::Type
just fine but the resulting signature is '()' which, I believe, is invalid. Or at least the parser can't handle it since this change.
If I revert the linked commit, everything seems to work fine in my case, so maybe reverting it could be a solution. But I don't know why that change was made. And I am really not sure if '()' is a valid signature in the first place, I didn't find it in the specification. So maybe a struct without fields should instead be handled like a unit struct? (Which seems to produce an empty string as signature.)
Anyway, deriving a signature that can't be parsed is not ideal, right? What do you think is the right solution?
Minimal reproducing example:
use zvariant::Type;
#[derive(serde::Serialize, serde::Deserialize, zvariant::Type)]
struct EmptyStruct {}
#[test]
fn test_name() {
let ctxt = zvariant::EncodingContext::<byteorder::LE>::new_dbus(0);
let value = EmptyStruct {};
println!("Signature: '{}'", EmptyStruct::signature());
let bytes = zvariant::to_bytes(ctxt, &value).expect("couldn't write");
let _value: EmptyStruct = zvariant::from_slice(&bytes, ctxt).expect("couldn't read");
}
which prints
running 1 test
Signature: '()'
thread 'tests::test_name' panicked at 'couldn't write: Message("invalid length 2, expected >= 2 characters")', src/lib.rs:60:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace