Re: [PATCH v1 3/5] rust: time: Add HrTimerExpires trait
From: FUJITA Tomonori
Date: Tue Jun 03 2025 - 09:52:27 EST
On Fri, 30 May 2025 15:04:00 +0200
Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>> +/// Defines a new `HrTimerMode` implementation with a given expiration type and C mode.
>> +#[doc(hidden)]
>> +macro_rules! define_hrtimer_mode {
>> + (
>> + $(#[$meta:meta])*
>> + $vis:vis struct $name:ident<$clock:ident> {
>> + c = $mode:ident,
>> + expires = $expires:ty
>> + }
>> + ) => {
>> + $(#[$meta])*
>> + $vis struct $name<$clock: $crate::time::ClockSource>(
>> + ::core::marker::PhantomData<$clock>
>> + );
>
> I think a macro is too much here. The code would be easier to read
> without the macro, and the macro does not remove much code here.
>
> Could you try to do the trait implementations without the macro?
Something like the following, right? If so, I'll do in the next
version. I'm also fine with that way.
/// Timer that expires at a fixed point in time.
pub struct AbsoluteMode<C: ClockSource>(PhantomData<C>);
impl<C: ClockSource> HrTimerMode for AbsoluteMode<C> {
const C_MODE: bindings::hrtimer_mode = bindings::hrtimer_mode_HRTIMER_MODE_ABS;
type Clock = C;
type Expires = Instant<C>;
}
instead of
define_hrtimer_mode! {
/// Timer that expires at a fixed point in time.
pub struct AbsoluteMode<C> {
c = HRTIMER_MODE_ABS,
expires = Instant<C>
}
}