Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
//! timerfd in the first place: Because it creates a file descriptor
//! that you can monitor with `select(2)`, `poll(2)` and `epoll(2)`.
//!
//! In other words, the only advantage this offers over any other
//! timer implementation is that it implements the `AsRawFd` trait.
//! In other words, the primary advantage this offers over any other
//! timer implementation is that it implements the `AsFd`/`AsRawFd` traits.
//!
//! The file descriptor becomes ready/readable whenever the timer expires.
#![warn(missing_debug_implementations)]
Expand All @@ -47,6 +47,7 @@ use std::os::unix::prelude::*;
use std::time::Duration;
use std::io::Result as IoResult;
use std::fmt;
use rustix::fd::{AsFd, BorrowedFd, OwnedFd};
use rustix::time::{Itimerspec, TimerfdClockId};

#[derive(Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -152,7 +153,7 @@ pub enum TimerState {
///
/// [`timerfd_create(2)`]: http://man7.org/linux/man-pages/man2/timerfd_create.2.html
#[derive(Debug)]
pub struct TimerFd(rustix::fd::OwnedFd);
pub struct TimerFd(OwnedFd);

impl TimerFd {
/// Creates a new `TimerFd`.
Expand Down Expand Up @@ -251,6 +252,18 @@ impl FromRawFd for TimerFd {
}
}

impl AsFd for TimerFd {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}

impl From<TimerFd> for OwnedFd {
fn from(fd: TimerFd) -> OwnedFd {
fd.0
}
}

#[cfg(test)]
mod tests {
extern crate rustix;
Expand Down