fast_time 0.1.24

An efficient low-precision timestamp source suitable for high-frequency querying
Documentation
use crate::pal::linux::BindingsFacade;
use crate::pal::{Platform, TimeSourceImpl};

/// Singleton instance of `BuildTargetPlatform`, used by public API types
/// to hook up to the correct PAL implementation.
pub(crate) static BUILD_TARGET_PLATFORM: BuildTargetPlatform =
    BuildTargetPlatform::new(BindingsFacade::real());

#[derive(Debug)]
pub(crate) struct BuildTargetPlatform {
    bindings: BindingsFacade,
}

impl BuildTargetPlatform {
    // Only executed in const context.
    #[cfg_attr(coverage_nightly, coverage(off))]
    pub(crate) const fn new(bindings: BindingsFacade) -> Self {
        Self { bindings }
    }
}

impl Platform for BuildTargetPlatform {
    type TimeSource = TimeSourceImpl;

    fn new_time_source(&self) -> Self::TimeSource {
        Self::TimeSource::new(self.bindings.clone())
    }
}

#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
    use std::panic::{RefUnwindSafe, UnwindSafe};

    use super::*;

    static_assertions::assert_impl_all!(BuildTargetPlatform: UnwindSafe, RefUnwindSafe);
}