lucab / zbus_systemd

A pure-Rust library to interact with systemd DBus services
https://docs.rs/zbus_systemd
27 stars 7 forks source link

Generate nicer return structs #27

Open bouk opened 8 months ago

bouk commented 8 months ago

You can define structs to map types to in zbus: https://dbus2.github.io/zbus/client.html

It'd be nice if e.g. list_units returned a Vec like:

struct Unit {
    name: String,
    description: String,
    load_state: String,
    active_state: String,
    sub_state: String,
    followed_unit: String,
    path: OwnedObjectPath,
    job_id: u32,
    job_type: String,
    job_object_path: OwnedObjectPath,
}

Instead of the Vec of tuples we have right now

lucab commented 8 months ago

Thanks for the feedback. I agree this kind of struct would be more ergonomic to handle, but at the same time I don't currently see a way to fully autogenerate them.

Continuing with the ListUnits example you mentioned, the only information we have in the XML descriptor is:

ListUnits(out a(ssssssouso) units);

I think this feature would require manually adding the struct definition and then either adding some overrides in the configuration or some automatic heuristic in the code-generator.

Did you maybe have something else in mind?