Re: [PATCH v2 12/16] scripts/qapi: generate high-level Rust bindings

Markus Armbruster
2026-02-24T13:46:53Z

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 2/23/26 13:36, Markus Armbruster wrote:
>> Paolo Bonzini <pbonzini@redhat.com> writes:
>>
>>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>
>>> Generate high-level native Rust declarations for the QAPI types.
>>>
>>> - char* is mapped to String, scalars to there corresponding Rust types
>>>
>>> - enums use #[repr(u32)] and can be transmuted to their C counterparts
>>>
>>> - has_foo/foo members are mapped to Option<T>
>>>
>>> - lists are represented as Vec<T>
>>>
>>> - structures map fields 1:1 to Rust
>>>
>>> - alternate are represented as Rust enum, each variant being a 1-element
>>> tuple
>>>
>>> - unions are represented in a similar way as in C: a struct S with a "u"
>>> member (since S may have extra 'base' fields). The discriminant
>>> isn't a member of S, since Rust enum already include it, but it can be
>>> recovered with "mystruct.u.into()"
>>>
>>> Anything that includes a recursive struct puts it in a Box. Lists are
>>> not considered recursive, because Vec breaks the recursion (it's possible
>>> to construct an object containing an empty Vec of its own type).
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> Link: https://lore.kernel.org/r/20210907121943.3498701-21-marcandre.lureau@redhat.com
>>> [Paolo: rewrite conversion of schema types to Rust types]
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>
>> Please mention how to actually generate Rust, because it's anything but
>> obvious: pass -B qapi.backend.QAPIRsBackend to qapi-gen.py. Recommend
>> to mention it again in the cover letter.
>>
>> Additionally, state that this is a hack we'll want to replace both in
>> the commit message and a TODO comment. See review of v1's cover letter
>> for why.
>
> Yes, the TODO comment is in patch 14 where the thing actually gets used.
> I can make it more prominent.

I missed the comment, because I looked for it here, and not in PATCH 14.
The comment is fine as is. However, we could have another comment near
QAPIRsBackend in this patch.