Re: [PATCH] rust: kernel: make impl_has_work compatible with more complex generics

From: Benno Lossin
Date: Mon May 27 2024 - 05:06:08 EST


On 22.05.24 14:37, Alice Ryhl wrote:
> On Wed, May 22, 2024 at 2:27 PM mu001999 <mu001999@xxxxxxxxxxx> wrote:
>> impl_has_work! {
>> - impl<T> HasWork<Self> for ClosureWork<T> { self.work }
>> + impl{T} HasWork<Self> for ClosureWork<T> { self.work }
>> }
>
> I ended up doing something similar for the generics in some of the
> linked list patches. Does anyone know if it's possible to support this
> without giving up the <T> syntax?

I tried to come up with something some time ago, but it was not really
nice. You have to parse the entire generics manually, which ends up
looking horrible. I have been thinking some time now that a `generics`
fragment would actually be really useful in declarative macros.

I also thought that if we get even more `Has*` traits for intrusive
datastructures, we could add a unified derive macro that allows you to
just do:

#[derive(Intrusive)]
struct MyStruct {
#[intrusive]
work: Work<Self>,
#[intrusive]
timer: Timer<Self>,
/* ... */
}

But I thought that as long as we have only two intrusive structures, we
don't need this.

---
Cheers,
Benno