Il gio 19 feb 2026, 14:39 Markus Armbruster <[email protected]> ha scritto:
> Paolo Bonzini <[email protected]> writes: > > > 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. > > To and from generated Rust structs, I presume. > Yes, or enums—and actually any (de)serializable Rust type, of which QAPI structs should be the most common case. > As an example of how this would be used, the marshaling functions for > > QMP commands would look like this: > > > > 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) }, > > } > > } > > Scoring 0.23 UOUPNBL (uses of unsafe per non-blank line). SCNR! > Well, that's why you automatically generate this! You could also use only one or two unsafe blocks but I preferred to mark explicitly the code that requires it. Paolo > > Despite the long v1->v2, the changes are mostly cosmetic; there are a few > > small differences in the detection of types to be wrapped with Box<>, > > because Vec<> is now considered to break cycles. > > > > Available at branch rust-next of https://gitlab.com/bonzini/qemu (which > > is now almost empty other than this series, yay). > > > > Paolo > >
