Skip to content

Commit

Permalink
impl Debug for AioCb and SigevNotify
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Feb 24, 2017
1 parent 3c25561 commit 7ebae9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use {Error, Errno, Result};
use std::os::unix::io::RawFd;
use libc::{c_void, off_t, size_t};
use libc;
use std::fmt;
use std::fmt::Debug;
use std::io::Write;
use std::io::stderr;
use std::marker::PhantomData;
Expand Down Expand Up @@ -270,6 +272,23 @@ pub fn lio_listio(mode: LioMode, list: &[&mut AioCb],
}).map(drop)
}

impl<'a> Debug for AioCb<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("AioCb")
.field("aio_fildes", &self.aiocb.aio_fildes)
.field("aio_offset", &self.aiocb.aio_offset)
.field("aio_buf", &self.aiocb.aio_buf)
.field("aio_nbytes", &self.aiocb.aio_nbytes)
.field("aio_lio_opcode", &self.aiocb.aio_lio_opcode)
.field("aio_reqprio", &self.aiocb.aio_reqprio)
.field("aio_sigevent", &SigEvent::from(&self.aiocb.aio_sigevent))
.field("mutable", &self.mutable)
.field("in_progress", &self.in_progress)
.field("phantom", &self.phantom)
.finish()
}
}

impl<'a> Drop for AioCb<'a> {
/// If the `AioCb` has no remaining state in the kernel, just drop it.
/// Otherwise, collect its error and return values, so as not to leak
Expand Down
31 changes: 31 additions & 0 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use libc;
use {Errno, Error, Result};
use std::fmt;
use std::fmt::Debug;
use std::mem;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
Expand Down Expand Up @@ -505,6 +507,35 @@ impl SigEvent {
}
}

impl Debug for SigEvent {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("SigEvent")
.field("sigev_notify", &self.sigevent.sigev_notify)
.field("sigev_signo", &self.sigevent.sigev_signo)
.field("sigev_value", &self.sigevent.sigev_value.sival_ptr)
.field("sigev_notify_thread_id",
&self.sigevent.sigev_notify_thread_id)
.finish()
}

#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("SigEvent")
.field("sigev_notify", &self.sigevent.sigev_notify)
.field("sigev_signo", &self.sigevent.sigev_signo)
.field("sigev_value", &self.sigevent.sigev_value.sival_ptr)
.field("sigev_notify_thread_id",
&self.sigevent.sigev_notify_thread_id)
.finish()
}
}

impl<'a> From<&'a libc::sigevent> for SigEvent {
fn from(sigevent: &libc::sigevent) -> Self {
SigEvent{ sigevent: sigevent.clone() }
}
}

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 7ebae9a

Please sign in to comment.