Re: [PATCH 1/2] rust: drm: add support for driver features

From: Daniel Almeida

Date: Wed Jan 21 2026 - 14:05:52 EST


Hi Gary,

> On 21 Jan 2026, at 14:31, Gary Guo <gary@xxxxxxxxxxx> wrote:
>
> On Mon Jan 19, 2026 at 11:34 PM GMT, Daniel Almeida wrote:
>> Add initial support for drm driver features via the DriverFeatures trait.
>> This trait is unsafe, requiring the implementer to comply with the safety
>> requirements of each feature individually if the feature is enabled.
>
> I think such unsafe requirement is quite vague and also very non-local.
>
> Maybe we can use a single trait (the `ModesetOps` that you described) to do
> this:
>
> Something like:
>
> pub unsafe trait ModesetOps<D> { ... }
>
> // Maybe the never type in the future...
> pub enum NoFeature {}
>
> impl<D> ModesetOps<D> for NoFeature {
> fn foo(&self, ...) { unimplemented!() }
> }
>
> impl Driver {
> /// Reference the modeset implementation (typically Self),
> /// or `NoFeature` to indicate that the feature is not implemented.
> type Modeset: ModesetOps<Self>;

Yeah, this looks better indeed. I assume we can have multiple features by
having multiple traits, right?

> }
>
> When building, you can use `TypeId` to check if it's actually implemented, and
> set bits in the feature flags automatically.
>
> Best,
> Gary

I assume we would enable FeatureFoo if typeid(Foo) != typeid(NoFeatureFoo)?

Where Foo is “type Foo: FooOps” in the Driver trait.