Re: [PATCH v2 00/16] rust: QObject and QAPI bindings

Daniel P. Berrangé
2026-02-23T09:55:22Z

On Thu, Jan 08, 2026 at 02:10:27PM +0100, Paolo Bonzini wrote:
> This adds two related parts of the Rust bindings:
>
> - QAPI code generator that creates Rust structs from the JSON
> description. The structs are *not* ABI compatible with the
> C ones, instead they use native Rust data types.
>
> - QObject bindings and (de)serialization support, which can be used to
> convert QObjects to and from QAPI structs.
>
> Unfortunately Rust code is not able to use visitors, other than by
> creating an intermediate QObject. This is because of the different
> architecture of serde vs. QAPI visitors, and because visitor's
> dual-purpose functions, where the same function is used by both input and
> output visitors, rely heavily on the structs using the same representation
> as the visitor arguments (for example NUL-terminated strings).
>
> The serde format implementation was co-authored by me and Marc-André.
> Marc-André did all the bug fixing and integration testing.
>
> As an example of how this would be used, the marshaling functions for
> QMP commands would look like this:

Can you give more of the big picture about what follows this ? From
this example you're showing, are you suggesting that you'll be soon
moving QMP command impls from C to Rust ?

>
> fn qmp_marshal_query_stats(args: *mut QDict,
> retp: *mut *mut QObject, errp: *mut *mut Error)
> {
> let qobj = unsafe { QObject::cloned_from_raw(args.cast()) };
>
> let result = from_qobject::<StatsFilter>(qobj)
> .map_err(anyhow::Error::from)
> .and_then(qmp_query_stats)
> .and_then(|ret| to_qobject::<Vec<StatsResult>>(ret).map_err(anyhow::Error::from));
>
> match qmp_marshal_query_stats_rs(qobj) {
> Ok(ret) => unsafe { *retp = ret.into_raw(); },
> Err(e) => unsafe { crate::Error::from(e).propagate(errp) },
> }
> }
>

With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|