Skip to content

Commit 0479344

Browse files
committed
Add extra traits for NetBSD
1 parent 2099a92 commit 0479344

File tree

1 file changed

+295
-8
lines changed
  • src/unix/bsd/netbsdlike/netbsd

1 file changed

+295
-8
lines changed

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 295 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,12 @@ s! {
274274
}
275275

276276
s_no_extra_traits! {
277-
#[allow(missing_debug_implementations)]
278277
pub struct in_pktinfo {
279278
pub ipi_addr: ::in_addr,
280279
pub ipi_ifindex: ::c_uint,
281280
}
282281

283282
#[repr(packed)]
284-
#[allow(missing_debug_implementations)]
285283
pub struct arphdr {
286284
pub ar_hrd: u16,
287285
pub ar_pro: u16,
@@ -291,18 +289,15 @@ s_no_extra_traits! {
291289
}
292290

293291
#[repr(packed)]
294-
#[allow(missing_debug_implementations)]
295292
pub struct in_addr {
296293
pub s_addr: ::in_addr_t,
297294
}
298295

299-
#[allow(missing_debug_implementations)]
300296
pub struct ip_mreq {
301297
pub imr_multiaddr: in_addr,
302298
pub imr_interface: in_addr,
303299
}
304300

305-
#[allow(missing_debug_implementations)]
306301
pub struct sockaddr_in {
307302
pub sin_len: u8,
308303
pub sin_family: ::sa_family_t,
@@ -311,7 +306,6 @@ s_no_extra_traits! {
311306
pub sin_zero: [::int8_t; 8],
312307
}
313308

314-
#[allow(missing_debug_implementations)]
315309
pub struct dirent {
316310
pub d_fileno: ::ino_t,
317311
pub d_reclen: u16,
@@ -320,7 +314,6 @@ s_no_extra_traits! {
320314
pub d_name: [::c_char; 512],
321315
}
322316

323-
#[allow(missing_debug_implementations)]
324317
pub struct statvfs {
325318
pub f_flag: ::c_ulong,
326319
pub f_bsize: ::c_ulong,
@@ -355,7 +348,6 @@ s_no_extra_traits! {
355348
pub f_mntfromname: [::c_char; 1024],
356349
}
357350

358-
#[allow(missing_debug_implementations)]
359351
pub struct sockaddr_storage {
360352
pub ss_len: u8,
361353
pub ss_family: ::sa_family_t,
@@ -365,6 +357,301 @@ s_no_extra_traits! {
365357
}
366358
}
367359

360+
cfg_if! {
361+
if #[cfg(feature = "extra_traits")] {
362+
impl PartialEq for in_pktinfo {
363+
fn eq(&self, other: &in_pktinfo) -> bool {
364+
self.ipi_addr == other.ipi_addr
365+
&& self.ipi_ifindex == other.ipi_ifindex
366+
}
367+
}
368+
impl Eq for in_pktinfo {}
369+
impl ::fmt::Debug for in_pktinfo {
370+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
371+
f.debug_struct("in_pktinfo")
372+
.field("ipi_addr", &self.ipi_addr)
373+
.field("ipi_ifindex", &self.ipi_ifindex)
374+
.finish()
375+
}
376+
}
377+
impl ::hash::Hash for in_pktinfo {
378+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
379+
self.ipi_addr.hash(state);
380+
self.ipi_ifindex.hash(state);
381+
}
382+
}
383+
384+
impl PartialEq for arphdr {
385+
fn eq(&self, other: &arphdr) -> bool {
386+
self.ar_hrd == other.ar_hrd
387+
&& self.ar_pro == other.ar_pro
388+
&& self.ar_hln == other.ar_hln
389+
&& self.ar_pln == other.ar_pln
390+
&& self.ar_op == other.ar_op
391+
}
392+
}
393+
impl Eq for arphdr {}
394+
impl ::fmt::Debug for arphdr {
395+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
396+
f.debug_struct("arphdr")
397+
.field("ar_hrd", &self.ar_hrd)
398+
.field("ar_pro", &self.ar_pro)
399+
.field("ar_hln", &self.ar_hln)
400+
.field("ar_pln", &self.ar_pln)
401+
.field("ar_op", &self.ar_op)
402+
.finish()
403+
}
404+
}
405+
impl ::hash::Hash for arphdr {
406+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
407+
self.ar_hrd.hash(state);
408+
self.ar_pro.hash(state);
409+
self.ar_hln.hash(state);
410+
self.ar_pln.hash(state);
411+
self.ar_op.hash(state);
412+
}
413+
}
414+
415+
impl PartialEq for in_addr {
416+
fn eq(&self, other: &in_addr) -> bool {
417+
self.s_addr == other.s_addr
418+
}
419+
}
420+
impl Eq for in_addr {}
421+
impl ::fmt::Debug for in_addr {
422+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
423+
f.debug_struct("in_addr")
424+
.field("s_addr", &self.s_addr)
425+
.finish()
426+
}
427+
}
428+
impl ::hash::Hash for in_addr {
429+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
430+
self.s_addr.hash(state);
431+
}
432+
}
433+
434+
impl PartialEq for ip_mreq {
435+
fn eq(&self, other: &ip_mreq) -> bool {
436+
self.imr_multiaddr == other.imr_multiaddr
437+
&& self.imr_interface == other.imr_interface
438+
}
439+
}
440+
impl Eq for ip_mreq {}
441+
impl ::fmt::Debug for ip_mreq {
442+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
443+
f.debug_struct("ip_mreq")
444+
.field("imr_multiaddr", &self.imr_multiaddr)
445+
.field("imr_interface", &self.imr_interface)
446+
.finish()
447+
}
448+
}
449+
impl ::hash::Hash for ip_mreq {
450+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
451+
self.imr_multiaddr.hash(state);
452+
self.imr_interface.hash(state);
453+
}
454+
}
455+
456+
impl PartialEq for sockaddr_in {
457+
fn eq(&self, other: &sockaddr_in) -> bool {
458+
self.sin_len == other.sin_len
459+
&& self.sin_family == other.sin_family
460+
&& self.sin_port == other.sin_port
461+
&& self.sin_addr == other.sin_addr
462+
&& self.sin_zero == other.sin_zero
463+
}
464+
}
465+
impl Eq for sockaddr_in {}
466+
impl ::fmt::Debug for sockaddr_in {
467+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
468+
f.debug_struct("sockaddr_in")
469+
.field("sin_len", &self.sin_len)
470+
.field("sin_family", &self.sin_family)
471+
.field("sin_port", &self.sin_port)
472+
.field("sin_addr", &self.sin_addr)
473+
.field("sin_zero", &self.sin_zero)
474+
.finish()
475+
}
476+
}
477+
impl ::hash::Hash for sockaddr_in {
478+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
479+
self.sin_len.hash(state);
480+
self.sin_family.hash(state);
481+
self.sin_port.hash(state);
482+
self.sin_addr.hash(state);
483+
self.sin_zero.hash(state);
484+
}
485+
}
486+
487+
impl PartialEq for dirent {
488+
fn eq(&self, other: &dirent) -> bool {
489+
self.d_fileno == other.d_fileno
490+
&& self.d_reclen == other.d_reclen
491+
&& self.d_namlen == other.d_namlen
492+
&& self.d_type == other.d_type
493+
&& self
494+
.d_name
495+
.iter()
496+
.zip(other.d_name.iter())
497+
.all(|(a,b)| a == b)
498+
}
499+
}
500+
impl Eq for dirent {}
501+
impl ::fmt::Debug for dirent {
502+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
503+
f.debug_struct("dirent")
504+
.field("d_fileno", &self.d_fileno)
505+
.field("d_reclen", &self.d_reclen)
506+
.field("d_namlen", &self.d_namlen)
507+
.field("d_type", &self.d_type)
508+
// FIXME: .field("d_name", &self.d_name)
509+
.finish()
510+
}
511+
}
512+
impl ::hash::Hash for dirent {
513+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
514+
self.d_fileno.hash(state);
515+
self.d_reclen.hash(state);
516+
self.d_namlen.hash(state);
517+
self.d_type.hash(state);
518+
self.d_name.hash(state);
519+
}
520+
}
521+
522+
impl PartialEq for statvfs {
523+
fn eq(&self, other: &statvfs) -> bool {
524+
self.f_flag == other.f_flag
525+
&& self.f_bsize == other.f_bsize
526+
&& self.f_frsize == other.f_frsize
527+
&& self.f_iosize == other.f_iosize
528+
&& self.f_blocks == other.f_blocks
529+
&& self.f_bfree == other.f_bfree
530+
&& self.f_bavail == other.f_bavail
531+
&& self.f_bresvd == other.f_bresvd
532+
&& self.f_files == other.f_files
533+
&& self.f_ffree == other.f_ffree
534+
&& self.f_favail == other.f_favail
535+
&& self.f_fresvd == other.f_fresvd
536+
&& self.f_syncreads == other.f_syncreads
537+
&& self.f_syncwrites == other.f_syncwrites
538+
&& self.f_asyncreads == other.f_asyncreads
539+
&& self.f_asyncwrites == other.f_asyncwrites
540+
&& self.f_fsidx == other.f_fsidx
541+
&& self.f_fsid == other.f_fsid
542+
&& self.f_namemax == other.f_namemax
543+
&& self.f_owner == other.f_owner
544+
&& self.f_spare == other.f_spare
545+
&& self.f_fstypename == other.f_fstypename
546+
&& self
547+
.f_mntonname
548+
.iter()
549+
.zip(other.f_mntonname.iter())
550+
.all(|(a,b)| a == b)
551+
&& self
552+
.f_mntfromname
553+
.iter()
554+
.zip(other.f_mntfromname.iter())
555+
.all(|(a,b)| a == b)
556+
}
557+
}
558+
impl Eq for statvfs {}
559+
impl ::fmt::Debug for statvfs {
560+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
561+
f.debug_struct("statvfs")
562+
.field("f_flag", &self.f_flag)
563+
.field("f_bsize", &self.f_bsize)
564+
.field("f_frsize", &self.f_frsize)
565+
.field("f_iosize", &self.f_iosize)
566+
.field("f_blocks", &self.f_blocks)
567+
.field("f_bfree", &self.f_bfree)
568+
.field("f_bavail", &self.f_bavail)
569+
.field("f_bresvd", &self.f_bresvd)
570+
.field("f_files", &self.f_files)
571+
.field("f_ffree", &self.f_ffree)
572+
.field("f_favail", &self.f_favail)
573+
.field("f_fresvd", &self.f_fresvd)
574+
.field("f_syncreads", &self.f_syncreads)
575+
.field("f_syncwrites", &self.f_syncwrites)
576+
.field("f_asyncreads", &self.f_asyncreads)
577+
.field("f_asyncwrites", &self.f_asyncwrites)
578+
.field("f_fsidx", &self.f_fsidx)
579+
.field("f_fsid", &self.f_fsid)
580+
.field("f_namemax", &self.f_namemax)
581+
.field("f_owner", &self.f_owner)
582+
.field("f_spare", &self.f_spare)
583+
.field("f_fstypename", &self.f_fstypename)
584+
// FIXME: .field("f_mntonname", &self.f_mntonname)
585+
// FIXME: .field("f_mntfromname", &self.f_mntfromname)
586+
.finish()
587+
}
588+
}
589+
impl ::hash::Hash for statvfs {
590+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
591+
self.f_flag.hash(state);
592+
self.f_bsize.hash(state);
593+
self.f_frsize.hash(state);
594+
self.f_iosize.hash(state);
595+
self.f_blocks.hash(state);
596+
self.f_bfree.hash(state);
597+
self.f_bavail.hash(state);
598+
self.f_bresvd.hash(state);
599+
self.f_files.hash(state);
600+
self.f_ffree.hash(state);
601+
self.f_favail.hash(state);
602+
self.f_fresvd.hash(state);
603+
self.f_syncreads.hash(state);
604+
self.f_syncwrites.hash(state);
605+
self.f_asyncreads.hash(state);
606+
self.f_asyncwrites.hash(state);
607+
self.f_fsidx.hash(state);
608+
self.f_fsid.hash(state);
609+
self.f_namemax.hash(state);
610+
self.f_owner.hash(state);
611+
self.f_spare.hash(state);
612+
self.f_fstypename.hash(state);
613+
self.f_mntonname.hash(state);
614+
self.f_mntfromname.hash(state);
615+
}
616+
}
617+
618+
impl PartialEq for sockaddr_storage {
619+
fn eq(&self, other: &sockaddr_storage) -> bool {
620+
self.ss_len == other.ss_len
621+
&& self.ss_family == other.ss_family
622+
&& self.__ss_pad1 == other.__ss_pad1
623+
&& self.__ss_pad2 == other.__ss_pad2
624+
&& self
625+
.__ss_pad3
626+
.iter()
627+
.zip(other.__ss_pad3.iter())
628+
.all(|(a,b)| a == b)
629+
}
630+
}
631+
impl Eq for sockaddr_storage {}
632+
impl ::fmt::Debug for sockaddr_storage {
633+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
634+
f.debug_struct("sockaddr_storage")
635+
.field("ss_len", &self.ss_len)
636+
.field("ss_family", &self.ss_family)
637+
.field("__ss_pad1", &self.__ss_pad1)
638+
.field("__ss_pad2", &self.__ss_pad2)
639+
// FIXME: .field("__ss_pad3", &self.__ss_pad3)
640+
.finish()
641+
}
642+
}
643+
impl ::hash::Hash for sockaddr_storage {
644+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
645+
self.ss_len.hash(state);
646+
self.ss_family.hash(state);
647+
self.__ss_pad1.hash(state);
648+
self.__ss_pad2.hash(state);
649+
self.__ss_pad3.hash(state);
650+
}
651+
}
652+
}
653+
}
654+
368655
pub const AT_FDCWD: ::c_int = -100;
369656
pub const AT_EACCESS: ::c_int = 0x100;
370657
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x200;

0 commit comments

Comments
 (0)