Skip to content

Commit 7ebae9a

Browse files
committed
impl Debug for AioCb and SigevNotify
1 parent 3c25561 commit 7ebae9a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/sys/aio.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use {Error, Errno, Result};
22
use std::os::unix::io::RawFd;
33
use libc::{c_void, off_t, size_t};
44
use libc;
5+
use std::fmt;
6+
use std::fmt::Debug;
57
use std::io::Write;
68
use std::io::stderr;
79
use std::marker::PhantomData;
@@ -270,6 +272,23 @@ pub fn lio_listio(mode: LioMode, list: &[&mut AioCb],
270272
}).map(drop)
271273
}
272274

275+
impl<'a> Debug for AioCb<'a> {
276+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
277+
fmt.debug_struct("AioCb")
278+
.field("aio_fildes", &self.aiocb.aio_fildes)
279+
.field("aio_offset", &self.aiocb.aio_offset)
280+
.field("aio_buf", &self.aiocb.aio_buf)
281+
.field("aio_nbytes", &self.aiocb.aio_nbytes)
282+
.field("aio_lio_opcode", &self.aiocb.aio_lio_opcode)
283+
.field("aio_reqprio", &self.aiocb.aio_reqprio)
284+
.field("aio_sigevent", &SigEvent::from(&self.aiocb.aio_sigevent))
285+
.field("mutable", &self.mutable)
286+
.field("in_progress", &self.in_progress)
287+
.field("phantom", &self.phantom)
288+
.finish()
289+
}
290+
}
291+
273292
impl<'a> Drop for AioCb<'a> {
274293
/// If the `AioCb` has no remaining state in the kernel, just drop it.
275294
/// Otherwise, collect its error and return values, so as not to leak

src/sys/signal.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
use libc;
55
use {Errno, Error, Result};
6+
use std::fmt;
7+
use std::fmt::Debug;
68
use std::mem;
79
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
810
use std::os::unix::io::RawFd;
@@ -505,6 +507,35 @@ impl SigEvent {
505507
}
506508
}
507509

510+
impl Debug for SigEvent {
511+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
512+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
513+
fmt.debug_struct("SigEvent")
514+
.field("sigev_notify", &self.sigevent.sigev_notify)
515+
.field("sigev_signo", &self.sigevent.sigev_signo)
516+
.field("sigev_value", &self.sigevent.sigev_value.sival_ptr)
517+
.field("sigev_notify_thread_id",
518+
&self.sigevent.sigev_notify_thread_id)
519+
.finish()
520+
}
521+
522+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
523+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
524+
fmt.debug_struct("SigEvent")
525+
.field("sigev_notify", &self.sigevent.sigev_notify)
526+
.field("sigev_signo", &self.sigevent.sigev_signo)
527+
.field("sigev_value", &self.sigevent.sigev_value.sival_ptr)
528+
.field("sigev_notify_thread_id",
529+
&self.sigevent.sigev_notify_thread_id)
530+
.finish()
531+
}
532+
}
533+
534+
impl<'a> From<&'a libc::sigevent> for SigEvent {
535+
fn from(sigevent: &libc::sigevent) -> Self {
536+
SigEvent{ sigevent: sigevent.clone() }
537+
}
538+
}
508539

509540
#[cfg(test)]
510541
mod tests {

0 commit comments

Comments
 (0)