xmlgen fails to produce working code for org.freedesktop.systemd1
gdbus introspect --session --dest org.freedesktop.systemd1 \
--object-path /org/freedesktop/systemd1 --xml \
>src/org.freedesktop.systemd1.xml
zbus-xmlgen src/org.freedesktop.systemd1.xml >src/systemd1.rs
cargo build
The generated code fails to build with:
error[E0277]: the size for values of type `[(&str, zbus::zvariant::Value<'_>)]` cannot be known at compilation time
--> src/systemd1.rs:416:16
|
416 | arg_4: &[(&str, [(&str, zbus::zvariant::Value<'_>)])],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `(&str, [(&str, zbus::zvariant::Value<'_>)])`, the trait `Sized` is not implemented for `[(&str, zbus::zvariant::Value<'_>)]`
= note: required because it appears within the type `(&str, [(&str, zbus::zvariant::Value<'_>)])`
= note: slice and array elements must have `Sized` type
error: aborting due to previous error
The method causing error is:
StartTransientUnit(in s name,
in s mode,
in a(sv) properties,
in a(sa(sv)) aux,
out o job);
which gets turned into:
/// StartTransientUnit method
fn start_transient_unit(
&self,
arg_1: &str,
arg_2: &str,
arg_3: &[(&str, zbus::zvariant::Value<'_>)],
arg_4: &[(&str, [(&str, zbus::zvariant::Value<'_>)])],
) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
Changing the arg_4 definition to:
arg_4: &[(&str, &[(&str, zbus::zvariant::Value<'_>)])],
makes it build and at least works when passing an empty slice.
This change to xmlgen makes it generate output the same as the fixed version, but I don't know the code well enough to know whether it'd break something else so I'm wary of submitting it as a PR.
diff --git a/zbus_xmlgen/src/gen.rs b/zbus_xmlgen/src/gen.rs
index f3e839a..6807260 100644
--- a/zbus_xmlgen/src/gen.rs
+++ b/zbus_xmlgen/src/gen.rs
@@ -209,7 +209,7 @@ fn to_rust_type(ty: &str, input: bool, as_ref: bool) -> String {
_ => {
let ty = iter_to_rust_type(it, input, false);
if input {
- format!("{}[{}]", if as_ref { "&" } else { "" }, ty)
+ format!("&[{}]", ty)
} else {
format!("{}Vec<{}>", if as_ref { "&" } else { "" }, ty)
}