Re: [PATCH v3 1/2] rust: irq: add support for request_irq()

From: Alexandre Courbot
Date: Sun May 18 2025 - 09:24:39 EST


Hi Daniel,

On Thu May 15, 2025 at 4:20 AM JST, Daniel Almeida wrote:
<snip>
> +/// Callbacks for an IRQ handler.
> +pub trait Handler: Sync {
> + /// The actual handler function. As usual, sleeps are not allowed in IRQ
> + /// context.
> + fn handle_irq(&self) -> IrqReturn;
> +}
> +
> +impl<T: ?Sized + Handler + Send> Handler for Arc<T> {
> + fn handle_irq(&self) -> IrqReturn {
> + T::handle_irq(self)
> + }
> +}
> +
> +impl<T: ?Sized + Handler, A: Allocator> Handler for Box<T, A> {
> + fn handle_irq(&self) -> IrqReturn {
> + T::handle_irq(self)
> + }
> +}

I see that every smart pointer would have to implement Handler in order
to be used with this module, but...

> +#[pin_data(PinnedDrop)]
> +pub struct Registration<T: Handler> {
> + irq: u32,
> + #[pin]
> + handler: T,

... what if you store another type `U: Borrow<T>` here, and take it as
the argument of `register`? This way you should be able to use anything
that implements Borrow<T>, which includes T itself, Arc<T>, Box<T>, and
more, and can remove the two impl blocks above.