add default implementations delegating to ticks functionality#4
add default implementations delegating to ticks functionality#4datdenkikniet wants to merge 2 commits into
ticks functionality#4Conversation
cb41d39 to
9275f9f
Compare
nanos functionalityticks functionality
Having a tickrate of zero seems nonsensical, and gives rise to some cases where division could lead to div-by-zero.
9275f9f to
0cbc546
Compare
|
I thought about doing this. This is probably alright, but somehow, somewhere I feel like there's something wrong or missing with it. But I can't figure out what. So maybe it's alright? |
When time stuff is involved, I get often get this feeling too :P It really is just this straightforward, though. "Just" some time base conversion stuff. I think the difficult part about this is that, by having any methods based on some "defined unit of time", we're picking the minimum resolution and maximum value for the time we can operate on. Additionally, placing the responsibility of converting ns, ms, etc. completely with the And thirdly, the An alternative approach would be to just have some sort of "fugit light", (sorry for bringing it up again :P): #[derive(Clone, Copy)]
// Fugit equivalent: NanosDurationU64
struct Duration(u64);
impl Duration {
fn from_nanos(nanos: u64) -> { Self(nanos) }
fn from_micros(micros: u64) -> { todo!() }
// Etc. etc.
fn into_ticks(self, frequency: NonZeroU64) -> u64 { todo!() }
fn into_ticks_const<FREQ: u64>(&self) -> u64 { todo!() }
}
impl Into<core::time::Duration> for Duration {}
// Fugit equivalent: Instant<u64, 1, 1_000_000_000>
struct Instant(u64);
impl Instant {
fn from_ticks(ticks: u64, frequency: NonZeroU64) -> Self { todo!() }
}
impl Add<Duration> for Instant {}
impl Sub<Instant> for Instant {}
trait Timer {
fn now(&self) -> Instant { todo!() }
}
trait Alarm {
fn wait_until_ticks(&self, ticks: u64) { todo!() }
fn wait_until(&self, instant: Instant) { todo!() }
} |
Showing what I mean in #3
Perhaps the division is too expensive, or we should pick a different function as base (i.e. base everything around
microsinstead, since that is a "more realistic" resolution?)