timer-deque-rs 0.7.0

A OS based timer and timer queue which implements timeout queues of different types.
Documentation
/*-
 * timer-deque-rs - a Rust crate which provides timer and timer queues based on target OS
 *  functionality.
 * 
 * Copyright (C) 2025 Aleksandr Morozov alex@nixd.org
 *  4neko.org alex@4neko.org
 * 
 * The timer-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *                     
 *   2. The MIT License (MIT)
 *                     
 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
 */

/// A common code for the timer setup.
pub mod timer;

/// A common code for timer polling.
pub mod poll;

/// Linux specific code.
#[cfg(target_os = "linux")]
pub mod linux;



/// BSD specific code (including OSX as it is compat).
#[cfg(any(
    target_os = "freebsd",
    target_os = "dragonfly",
    target_os = "netbsd",
    target_os = "openbsd",
    target_os = "macos",
))]
pub mod bsd;

/// Windows specific code.
#[cfg(target_os = "windows")]
pub mod windows;


pub use timer::
{
    TimerFlags, 
    TimerType, 
    TimerSetTimeFlags, 
    TimerReadRes, 
    TimerExpMode, 
    FdTimerCom, 
    AbsoluteTime, 
    RelativeTime,
};

#[cfg(feature = "enable_mio_compat")]
pub use timer::TimerFdMioCompat;

pub use poll::{TimerPoll, PollEventType, PolledTimerFd, TimerPollOps};
pub use timer::{TimerFd, FdTimerMarker};

/// Error handling.
pub mod portable_error
{
    use std::fmt;

    use nix::errno::Errno;

    /// An error description.
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub struct TimerPortableErr
    {
        /// [Errno] error code
        last_err: Errno,

        /// Description
        msg: String
    }

    impl fmt::Display for TimerPortableErr
    {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
        {
            write!(f, "errno: '{}', msg: '{}'", self.last_err, self.msg)
        }
    }

    impl TimerPortableErr
    {
        pub 
        fn new(last_err: Errno, msg: String) -> Self
        {
            return Self{ last_err: last_err, msg: msg };
        }

        pub 
        fn get_errno(&self) -> Errno
        {
            return self.last_err;
        }
    }

    /// A `type` for [Result].
    pub type TimerPortResult<T> = Result<T, TimerPortableErr>;


    #[macro_export]
    macro_rules! portable_err 
    {
        ($last_err:expr,$($arg:tt)*) => (
            return std::result::Result::Err( $crate::timer_portable::portable_error::TimerPortableErr::new($last_err, format!($($arg)*)) )
        )
    }

    #[macro_export]
    macro_rules! map_portable_err 
    {
        ($last_err:expr,$($arg:tt)*) => (
            $crate::timer_portable::portable_error::TimerPortableErr::new($last_err, format!($($arg)*))
        )
    }
}