[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <0FD01582-58D1-4DC2-89DB-A4C8771F7750@collabora.com>
Date: Wed, 2 Jul 2025 10:14:04 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Boris Brezillon <boris.brezillon@...labora.com>,
Sebastian Reichel <sebastian.reichel@...labora.com>,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v6 1/2] rust: regulator: add a bare minimum regulator
abstraction
>
>>>> +impl<T: RegulatorState + 'static> Drop for Regulator<T> {
>>>> + fn drop(&mut self) {
>>>> + if core::any::TypeId::of::<T>() == core::any::TypeId::of::<Enabled>() {
>>>
>>> I would avoid this kind of logic. Instead, you can add an
>>> `disable_on_drop()` method or constant to the trait and check it here.
>>>
>>> Alice
>>>
>>
>> Can you expand on this?
>
> Along these lines:
>
> pub trait RegulatorState: 'static {
> const DISABLE_ON_DROP: bool;
> }
>
> impl RegulatorState for Enabled {
> const DISABLE_ON_DROP: bool = true;
> }
> impl RegulatorState for Disabled {
> const DISABLE_ON_DROP: bool = false;
> }
> impl RegulatorState for Dynamic {
> const DISABLE_ON_DROP: bool = false;
> }
>
> impl<T: RegulatorState> Drop for Regulator<T> {
> fn drop(&mut self) {
> if T::DISABLE_ON_DROP {
> unsafe { bindings::regulator_disable(self.inner.as_ptr()) };
> }
> unsafe { bindings::regulator_put(self.inner.as_ptr()) };
> }
> }
Ah, that indeed looks better, thanks.
— Daniel
Powered by blists - more mailing lists