|
From: | Paolo Bonzini |
Subject: | Re: [RFC 06/13] rust: add bindings for memattrs |
Date: | Thu, 23 Jan 2025 16:33:40 +0100 |
User-agent: | Mozilla Thunderbird |
On 1/23/25 16:10, Zhao Liu wrote:
Another solution would be to implement Zeroable for __BindgenBitfieldUnit in bindings.rs, but this is much nicer! It works even with old Rust versions and, even though it needs manual implementation of the trait each type, it doesn't require enumerating the fields one by one. So it's better than the current version of Zeroable and, if you wish, you can also replace existing implementations of Zeroable with const_zero.I'm working on this, and it's just a simple patch. But I'm not sure why Zeroable needs a Default constraint. I think Sized seems to be enough, doesn't it?
It's not needed but I think it makes sense semantically:1) the idea was that Default::default() would always return the same value as Zeroable::ZERO, apart possibly from padding. That is, for something that's Zeroable it should always make sense to use an all-zero value for Default::default(). And since there are standard library methods that use Default, the bound makes it possible to use them and know that they fill-with-zeroes.
2) I wasn't sure in which cases bindgen doesn't generate Default, if any; and with Default as a supertrait we'd have to double-check the first occurrence of a non-Default but zeroable struct.
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |