Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reexport aliases #3

Closed
andresv opened this issue Oct 29, 2021 · 5 comments
Closed

Reexport aliases #3

andresv opened this issue Oct 29, 2021 · 5 comments

Comments

@andresv
Copy link
Contributor

andresv commented Oct 29, 2021

Currently I have something like this:

use fugit::{ExtU32, aliases::MillisDurationU32};

pub struct SysTimer{
    start: fugit::Instant::<u32, 1, 1_000>,
    duration: MillisDurationU32,
}

I would prefer:

pub struct SysTimer{
    start: fugit::Instant::<u32, 1, 1_000>,
    duration: fugit::MillisDurationU32,
}

Actually maybe it makes sense to create aliases also for Instants?

@korken89
Copy link
Owner

Good catch, missed that!

@korken89
Copy link
Owner

On the other hand, does it make sense? Usually Instants have the speed of hardware timers which are far and spread.
While for an API Duration can be used to set the granularity you want in the API.
I have no problem adding the aliases, but I don't think Instant would see as much use as Duration.

What are your thoughts? @andresv

@korken89
Copy link
Owner

korken89 commented Oct 29, 2021

Maybe something like this makes more sense?

/// Alias for instants that come from timers with a specific frequency
pub type TimerInstant<T, const FREQ_HZ: u32> = Instant<T, 1, FREQ_HZ>;

/// Alias for instants that come from timers with a specific frequency (`u32` backing storage)
pub type TimerInstantU32<const FREQ_HZ: u32> = Instant<u32, 1, FREQ_HZ>;

/// Alias for instants that come from timers with a specific frequency (`u64` backing storage)
pub type TimerInstantU64<const FREQ_HZ: u32> = Instant<u64, 1, FREQ_HZ>;

@andresv
Copy link
Contributor Author

andresv commented Oct 29, 2021

const TIMER_FREQ_HZ: u32 = 1000;

// looking this first time might take some time to figure out what is going on here
Instant::<u32, 1, 1_000>

// I think this is more clear for a reader
TimerInstant::<u32, TIMER_FREQ_HZ>

Of course users can defines these aliases by themselves. Maybe there should be just an example in doc that shows it where it makes sense to define your own aliases.
Because indeed Instant can be what ever depending on hardware. Like Timer4Instant64Khz or something. So I think you are right and we do not need ready made aliases for them.

@andresv
Copy link
Contributor Author

andresv commented Oct 31, 2021

Seems to be fixed now.

@andresv andresv closed this as completed Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants