Re: [PATCH v4] rust: regulator: add a bare minimum regulator abstraction

From: Daniel Almeida
Date: Mon Jun 23 2025 - 14:32:50 EST


Hi Alex,

>> +
>> +/// A voltage in microvolts.
>> +///
>> +/// The explicit type is used to avoid confusion with other multiples of the
>> +/// volt, which can be desastrous.
>> +#[repr(transparent)]
>> +#[derive(Copy, Clone, PartialEq, Eq)]
>> +pub struct Microvolt(pub i32);
>
> This type actually contains a voltage, but is named after the unit it
> stores. A bit like if `Duration` was named `Nanoseconds`. How about just
> naming it `Voltage` and give it `from_microvolts` and `as_microvolts`
> methods? We might not need to use other units, but at least it doesn't
> close that option.

I think that not accepting anything other than microvolts is by design, and
that changing this to `Voltage` would defeat the purpose, which is to make it
crystal clear that the unit is microvolts.

Also, the places where this type is used take microvolts, so I don't see why we
should add this indirection, which would require a convertion back and forth
from volt.

By the way, I went ahead and sent a new version [0] without this change.

— Daniel

[0] https://lore.kernel.org/rust-for-linux/20250623-topics-tyr-regulator-v5-0-99069658cb54@xxxxxxxxxxxxx/T/#t