Re: [PATCH] rust: clk: use the type-state pattern

From: Benno Lossin
Date: Wed Jul 30 2025 - 04:20:28 EST


On Wed Jul 30, 2025 at 9:29 AM CEST, Daniel Sedlak wrote:
> On 7/29/25 11:38 PM, Daniel Almeida wrote:
>> + mod private {
>> + pub trait Sealed {}
>> +
>> + impl Sealed for super::Unprepared {}
>> + impl Sealed for super::Prepared {}
>> + impl Sealed for super::Enabled {}
>> + }
>
> I just noticed we have plenty of Sealed traits scattered across rust/
> folder. Do you think we would benefit from unifying it to a single
> location to prevent duplication?

I don't think we can merge the various `Sealed` traits we have. They are
implemented for different types and ensure that only those selected
types are allowed when `T: Sealed`. If we merge them, then that is no
longer the case.

We essentially would like to have a `#[sealed]` attribute that we can
put on a trait to avoid the `mod private { pub trait Sealed }` dance.
(so a trait that cannot be implemented outside of the module declaring
it)

---
Cheers,
Benno