Re: [PATCH v8 02/14] rust: hrtimer: introduce hrtimer support

From: Andreas Hindborg
Date: Fri Feb 21 2025 - 07:20:14 EST


"Benno Lossin" <benno.lossin@xxxxxxxxx> writes:

> On 21.02.25 11:15, Andreas Hindborg wrote:
>> Andreas Hindborg <a.hindborg@xxxxxxxxxx> writes:
>>
>>> "Benno Lossin" <benno.lossin@xxxxxxxxx> writes:
>>>
>>>> On 18.02.25 14:27, Andreas Hindborg wrote:
>>>>> +pub trait HrTimerCallback {
>>>>> + /// The type whose [`RawHrTimerCallback::run`] method will be invoked when
>>>>> + /// the timer expires.
>>>>> + type CallbackTarget<'a>: RawHrTimerCallback;
>>>>> +
>>>>> + /// This type is passed to the timer callback function. It may be a borrow
>>>>> + /// of [`Self::CallbackTarget`], or it may be `Self::CallbackTarget` if the
>>>>> + /// implementation can guarantee exclusive access to the target during timer
>>>>
>>>> Technically "exclusive" access is correct if the `CallbackTarget` is
>>>> `Pin<&Self>`, since you will get exclusive access to a `Pin<&Self>`, but
>>>> it might confuse people, because there can be multiple `Pin<&Self>`. So
>>>> I would just drop the word "exclusive" here.
>>>
>>> Yes, maybe it should be "shared or exclusive access, depending on the type"?
>>>
>>>>
>>>>> + /// handler execution.
>>>>> + type CallbackTargetParameter<'a>;
>>>>
>>>> Also why can't this type be an associated type of `HrTimerPointer`?
>>>> Since this seems to always be constrained in the impls of
>>>> `RawHrTimerCallback`.
>>>
>>> That might be a nice improvement, I'll try that out.
>>
>> Looking closer at this, I don't see how to achieve this. We need access
>> to the type here, because it is used in the signature of `run`.
>> `HrTimerCallback` has no bounds on it, and that is nice. If we want to
>> move these associated types, we have to introduce a bound here.
>>
>> We need to be generic over the type of the parameter to `run`, and by
>> the time the user implements this trait, the type must be known and so
>> the user has to specify somehow.
>
> I think if you put the associated type on the `RawHrTimerCallback`
> trait, it should work.

What would be the signature of `HrTimerCallback::run` in that case?


Best regards,
Andreas Hindborg