Sha256: 1477a07f66a69f50537994d501836f2b2ccf542a07a73d361043372357a93944

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

use crate::{backend, io};

pub use backend::time::types::{Nsecs, Secs, Timespec};

/// `clockid_t`
#[cfg(not(target_os = "wasi"))]
pub use backend::time::types::{ClockId, DynamicClockId};

/// `clock_getres(id)`—Returns the resolution of a clock.
///
/// # References
///  - [POSIX]
///  - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
/// [Linux]: https://man7.org/linux/man-pages/man2/clock_getres.2.html
#[cfg(any(not(any(target_os = "redox", target_os = "wasi"))))]
#[inline]
#[must_use]
pub fn clock_getres(id: ClockId) -> Timespec {
    backend::time::syscalls::clock_getres(id)
}

/// `clock_gettime(id)`—Returns the current value of a clock.
///
/// This function uses `ClockId` which only contains clocks which are known to
/// always be supported at runtime, allowing this function to be infallible.
/// For a greater set of clocks and dynamic clock support, see
/// [`clock_gettime_dynamic`].
///
/// # References
///  - [POSIX]
///  - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
#[must_use]
pub fn clock_gettime(id: ClockId) -> Timespec {
    backend::time::syscalls::clock_gettime(id)
}

/// Like [`clock_gettime`] but with support for dynamic clocks.
///
/// # References
///  - [POSIX]
///  - [Linux]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html
#[cfg(not(target_os = "wasi"))]
#[inline]
pub fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> {
    backend::time::syscalls::clock_gettime_dynamic(id)
}

Version data entries

8 entries across 7 versions & 1 rubygems

Version Path
wasmtime-8.0.0 ./ext/cargo-vendor/rustix-0.36.12/src/time/clock.rs
wasmtime-7.0.0 ./ext/cargo-vendor/rustix-0.36.11/src/time/clock.rs
wasmtime-7.0.0 ./ext/cargo-vendor/rustix-0.37.5/src/time/clock.rs
wasmtime-6.0.1 ./ext/cargo-vendor/rustix-0.36.8/src/time/clock.rs
wasmtime-6.0.0 ./ext/cargo-vendor/rustix-0.36.8/src/time/clock.rs
wasmtime-5.0.0 ./ext/cargo-vendor/rustix-0.36.7/src/time/clock.rs
wasmtime-0.4.1 ./ext/cargo-vendor/rustix-0.36.5/src/time/clock.rs
wasmtime-0.4.0 ./ext/cargo-vendor/rustix-0.36.5/src/time/clock.rs