Programming Language

Nocter

A self-contained systems language built around simplicity, encapsulation, and foolproof design.

/development/std/time/instant.nct

instant.nct

//! Opaque monotonic observations and target-independent conversion.

see ./index.nct
see ./duration.nct
see ./primitives.nct

copy struct Instant {
    counter: u64
}

construct Instant {
    noalloc func now(): Self {
        return Instant { counter: monotonic_counter_raw() }
    }
}

instance Instant {
    noalloc method &self.elapsed(): Duration {
        let current = monotonic_counter_raw()
        let delta = monotonic_delta_raw(self.counter, current)
        return duration_from_counter_delta(delta, monotonic_frequency_raw())
    }
}