Re: [PATCH 2/4] rust: device: implement device context marker

From: Danilo Krummrich
Date: Thu Mar 13 2025 - 06:41:26 EST


On Thu, Mar 13, 2025 at 10:29:35AM +0000, Benno Lossin wrote:
> On Thu Mar 13, 2025 at 3:13 AM CET, Danilo Krummrich wrote:
> > +/// Marker trait for the context of a bus specific device.
> > +///
> > +/// Some functions of a bus specific device should only be called from a certain context, i.e. bus
> > +/// callbacks, such as `probe()`.
> > +///
> > +/// This is the marker trait for structures representing the context of a bus specific device.
> > +pub trait DeviceContext {}
>
> I would make this trait sealed. ie:
>
> pub trait DeviceContext: private::Sealed {}
>
> mod private {
> pub trait Sealed {}
>
> impl Sealed for super::Core {}
> impl Sealed for super::Normal {}
> }
>
> Since currently a user can create a custom context (it will be useless,
> but then I think it still is better to give them a compile error).

That is intentional, some busses have bus specific callbacks, hence we may want
a bus specific context at some point.

However, we can always change visibility as needed, so I'm fine making it sealed
for now.

>
> If you make it sealed,
>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>