Re: [PATCH v4 4/5] rust: types: ForeignOwnable: Add type Target

From: Benno Lossin
Date: Thu Jun 26 2025 - 19:22:59 EST


On Thu Jun 26, 2025 at 10:00 PM CEST, Danilo Krummrich wrote:
> ForeignOwnable::Target defines the payload data of a ForeignOwnable. For
> Arc<T> for instance, ForeignOwnable::Target would just be T.
>
> This is useful for cases where a trait bound is required on the target
> type of the ForeignOwnable. For instance:
>
> fn example<P>(data: P)
> where
> P: ForeignOwnable,
> P::Target: MyTrait,
> {}
>
> Suggested-by: Benno Lossin <lossin@xxxxxxxxxx>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>

Reviewed-by: Benno Lossin <lossin@xxxxxxxxxx>

We might also be able to add a `Deref<Target = Self::Target>` bound on
`Borrowed` and `BorrowedMut`, but we should only do that when necessary.

---
Cheers,
Benno

> ---
> rust/kernel/alloc/kbox.rs | 2 ++
> rust/kernel/sync/arc.rs | 1 +
> rust/kernel/types.rs | 4 ++++
> 3 files changed, 7 insertions(+)