timer_deque_rs/timer_portable/
mod.rs1pub mod timer;
18
19pub mod poll;
21
22#[cfg(target_os = "linux")]
24pub mod linux;
25
26#[cfg(target_os = "linux")]
27pub use linux::timer_poll::TimerEventWatch;
28
29#[cfg(target_os = "linux")]
30pub type DefaultEventWatch = TimerEventWatch;
31
32#[cfg(any(
34 target_os = "freebsd",
35 target_os = "dragonfly",
36 target_os = "netbsd",
37 target_os = "openbsd",
38 target_os = "macos",
39))]
40pub mod bsd;
41
42#[cfg(
43 any(
44 target_os = "freebsd",
45 target_os = "dragonfly",
46 target_os = "netbsd",
47 target_os = "openbsd",
48 target_os = "macos",
49 )
50)]
51pub use bsd::TimerEventWatch;
52
53#[cfg(any(
54 target_os = "freebsd",
55 target_os = "dragonfly",
56 target_os = "netbsd",
57 target_os = "openbsd",
58 target_os = "macos",
59))]
60pub type DefaultEventWatch = TimerEventWatch;
61
62pub use timer::
63{
64 TimerFlags,
65 TimerType,
66 TimerSetTimeFlags,
67 TimerReadRes,
68 TimerExpMode,
69 FdTimerCom,
70 AbsoluteTime,
71 RelativeTime
72};
73pub use poll::{TimerPoll, PollEventType, PollResult};
74
75pub mod portable_error
77{
78 use std::fmt;
79
80 use nix::errno::Errno;
81
82 #[derive(Debug, Clone, PartialEq, Eq)]
84 pub struct TimerPortableErr
85 {
86 last_err: Errno,
88
89 msg: String
91 }
92
93 impl fmt::Display for TimerPortableErr
94 {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
96 {
97 write!(f, "errno: '{}', msg: '{}'", self.last_err, self.msg)
98 }
99 }
100
101 impl TimerPortableErr
102 {
103 pub
104 fn new(last_err: Errno, msg: String) -> Self
105 {
106 return Self{ last_err: last_err, msg: msg };
107 }
108
109 pub
110 fn get_errno(&self) -> Errno
111 {
112 return self.last_err;
113 }
114 }
115
116 pub type TimerPortResult<T> = Result<T, TimerPortableErr>;
118
119
120 #[macro_export]
121 macro_rules! portable_err
122 {
123 ($last_err:expr,$($arg:tt)*) => (
124 return std::result::Result::Err( $crate::timer_portable::portable_error::TimerPortableErr::new($last_err, format!($($arg)*)) )
125 )
126 }
127
128 #[macro_export]
129 macro_rules! map_portable_err
130 {
131 ($last_err:expr,$($arg:tt)*) => (
132 $crate::timer_portable::portable_error::TimerPortableErr::new($last_err, format!($($arg)*))
133 )
134 }
135}