Skip to content

Commit 0e1ee5c

Browse files
committed
Implement Debug for all types
1 parent 5a68377 commit 0e1ee5c

File tree

6 files changed

+131
-3
lines changed

6 files changed

+131
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ libc = { version = "0.2", features = ["align"] }
4545
```
4646

4747
All structs implemented by the libc crate have the `Copy` and `Clone` traits
48-
implemented for them. The additional traits of `PartialEq` and `Eq` can be
49-
enabled with the *extra_traits* feature (requires Rust 1.25 or newer):
48+
implemented for them. The additional traits of `Debug, `Eq`, and `PartialEq`
49+
can be enabled with the *extra_traits* feature (requires Rust 1.25 or newer):
5050

5151
```toml
5252
[dependencies]

src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ macro_rules! s {
4040
#[repr(C)]
4141
$(#[$attr])*
4242
#[derive(Clone, Copy)]
43-
#[cfg_attr(feature = "extra_traits", derive(Eq, PartialEq))]
43+
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, PartialEq))]
4444
pub $t $i { $($field)* }
4545
}
4646
)*)

src/unix/notbsd/linux/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,18 @@ impl PartialEq for dirent {
671671
}
672672
#[cfg(feature = "extra_traits")]
673673
impl Eq for dirent {}
674+
#[cfg(feature = "extra_traits")]
675+
impl std::fmt::Debug for dirent {
676+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
677+
f.debug_struct("dirent")
678+
.field("d_ino", &self.d_ino)
679+
.field("d_off", &self.d_off)
680+
.field("d_reclen", &self.d_reclen)
681+
.field("d_type", &self.d_type)
682+
// FIXME: .field("d_name", &self.d_name)
683+
.finish()
684+
}
685+
}
674686

675687
#[cfg(feature = "extra_traits")]
676688
impl PartialEq for dirent64 {
@@ -684,6 +696,18 @@ impl PartialEq for dirent64 {
684696
}
685697
#[cfg(feature = "extra_traits")]
686698
impl Eq for dirent64 {}
699+
#[cfg(feature = "extra_traits")]
700+
impl std::fmt::Debug for dirent64 {
701+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
702+
f.debug_struct("dirent64")
703+
.field("d_ino", &self.d_ino)
704+
.field("d_off", &self.d_off)
705+
.field("d_reclen", &self.d_reclen)
706+
.field("d_type", &self.d_type)
707+
// FIXME: .field("d_name", &self.d_name)
708+
.finish()
709+
}
710+
}
687711

688712
#[cfg(feature = "extra_traits")]
689713
impl PartialEq for pthread_cond_t {
@@ -693,6 +717,14 @@ impl PartialEq for pthread_cond_t {
693717
}
694718
#[cfg(feature = "extra_traits")]
695719
impl Eq for pthread_cond_t {}
720+
#[cfg(feature = "extra_traits")]
721+
impl std::fmt::Debug for pthread_cond_t {
722+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
723+
f.debug_struct("pthread_cond_t")
724+
// FIXME: .field("size", &self.size)
725+
.finish()
726+
}
727+
}
696728

697729
#[cfg(feature = "extra_traits")]
698730
impl PartialEq for pthread_mutex_t {
@@ -702,6 +734,14 @@ impl PartialEq for pthread_mutex_t {
702734
}
703735
#[cfg(feature = "extra_traits")]
704736
impl Eq for pthread_mutex_t {}
737+
#[cfg(feature = "extra_traits")]
738+
impl std::fmt::Debug for pthread_mutex_t {
739+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
740+
f.debug_struct("pthread_mutex_t")
741+
// FIXME: .field("size", &self.size)
742+
.finish()
743+
}
744+
}
705745

706746
#[cfg(feature = "extra_traits")]
707747
impl PartialEq for pthread_rwlock_t {
@@ -711,6 +751,14 @@ impl PartialEq for pthread_rwlock_t {
711751
}
712752
#[cfg(feature = "extra_traits")]
713753
impl Eq for pthread_rwlock_t {}
754+
#[cfg(feature = "extra_traits")]
755+
impl std::fmt::Debug for pthread_rwlock_t {
756+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
757+
f.debug_struct("pthread_rwlock_t")
758+
// FIXME: .field("size", &self.size)
759+
.finish()
760+
}
761+
}
714762

715763
pub const ABDAY_1: ::nl_item = 0x20000;
716764
pub const ABDAY_2: ::nl_item = 0x20001;

src/unix/notbsd/linux/other/b64/x86_64.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,23 @@ impl PartialEq for user_fpregs_struct {
255255
}
256256
#[cfg(feature = "extra_traits")]
257257
impl Eq for user_fpregs_struct {}
258+
#[cfg(feature = "extra_traits")]
259+
impl std::fmt::Debug for user_fpregs_struct {
260+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261+
f.debug_struct("user_fpregs_struct")
262+
.field("cwd", &self.cwd)
263+
.field("ftw", &self.ftw)
264+
.field("fop", &self.fop)
265+
.field("rip", &self.rip)
266+
.field("rdp", &self.rdp)
267+
.field("mxcsr", &self.mxcsr)
268+
.field("mxcr_mask", &self.mxcr_mask)
269+
.field("st_space", &self.st_space)
270+
// FIXME: .field("xmm_space", &self.xmm_space)
271+
// Ignore padding field
272+
.finish()
273+
}
274+
}
258275

259276
#[cfg(feature = "extra_traits")]
260277
impl PartialEq for ucontext_t {
@@ -269,6 +286,19 @@ impl PartialEq for ucontext_t {
269286
}
270287
#[cfg(feature = "extra_traits")]
271288
impl Eq for ucontext_t {}
289+
#[cfg(feature = "extra_traits")]
290+
impl std::fmt::Debug for ucontext_t {
291+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
292+
f.debug_struct("ucontext_t")
293+
.field("uc_flags", &self.uc_flags)
294+
.field("uc_link", &self.uc_link)
295+
.field("uc_stack", &self.uc_stack)
296+
.field("uc_mcontext", &self.uc_mcontext)
297+
.field("uc_sigmask", &self.uc_sigmask)
298+
// Ignore __private field
299+
.finish()
300+
}
301+
}
272302

273303
pub const TIOCGSOFTCAR: ::c_ulong = 0x5419;
274304
pub const TIOCSSOFTCAR: ::c_ulong = 0x541A;

src/unix/notbsd/linux/other/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ impl PartialEq for utmpx {
264264
}
265265
#[cfg(feature = "extra_traits")]
266266
impl Eq for utmpx {}
267+
#[cfg(feature = "extra_traits")]
268+
impl std::fmt::Debug for utmpx {
269+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
270+
f.debug_struct("utmpx")
271+
.field("ut_type", &self.ut_type)
272+
.field("ut_pid", &self.ut_pid)
273+
.field("ut_line", &self.ut_line)
274+
.field("ut_id", &self.ut_id)
275+
.field("ut_user", &self.ut_user)
276+
// FIXME: .field("ut_host", &self.ut_host)
277+
.field("ut_exit", &self.ut_exit)
278+
.field("ut_session", &self.ut_session)
279+
.field("ut_tv", &self.ut_tv)
280+
.field("ut_addr_v6", &self.ut_addr_v6)
281+
.field("__glibc_reserved", &self.__glibc_reserved)
282+
.finish()
283+
}
284+
}
267285

268286
pub const __UT_LINESIZE: usize = 32;
269287
pub const __UT_NAMESIZE: usize = 32;

src/unix/notbsd/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ impl PartialEq for sockaddr_un {
245245
}
246246
#[cfg(feature = "extra_traits")]
247247
impl Eq for sockaddr_un {}
248+
#[cfg(feature = "extra_traits")]
249+
impl std::fmt::Debug for sockaddr_un {
250+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
251+
f.debug_struct("sockaddr_un")
252+
.field("sun_family", &self.sun_family)
253+
// FIXME: .field("sun_path", &self.sun_path)
254+
.finish()
255+
}
256+
}
248257

249258
#[cfg(feature = "extra_traits")]
250259
impl PartialEq for sockaddr_storage {
@@ -259,6 +268,15 @@ impl PartialEq for sockaddr_storage {
259268
}
260269
#[cfg(feature = "extra_traits")]
261270
impl Eq for sockaddr_storage {}
271+
#[cfg(feature = "extra_traits")]
272+
impl std::fmt::Debug for sockaddr_storage {
273+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274+
f.debug_struct("sockaddr_storage")
275+
.field("ss_family", &self.ss_family)
276+
// FIXME: .field("__ss_pad2", &self.__ss_pad2)
277+
.finish()
278+
}
279+
}
262280

263281
#[cfg(feature = "extra_traits")]
264282
impl PartialEq for utsname {
@@ -296,6 +314,20 @@ impl PartialEq for utsname {
296314
}
297315
#[cfg(feature = "extra_traits")]
298316
impl Eq for utsname {}
317+
#[cfg(feature = "extra_traits")]
318+
impl std::fmt::Debug for utsname {
319+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
320+
f.debug_struct("utsname")
321+
// FIXME: .field("sysname", &self.sysname)
322+
// FIXME: .field("nodename", &self.nodename)
323+
// FIXME: .field("release", &self.release)
324+
// FIXME: .field("version", &self.version)
325+
// FIXME: .field("machine", &self.machine)
326+
// FIXME: .field("domainname", &self.domainname)
327+
.finish()
328+
}
329+
}
330+
299331
// intentionally not public, only used for fd_set
300332
cfg_if! {
301333
if #[cfg(target_pointer_width = "32")] {

0 commit comments

Comments
 (0)