Skip to content

Commit 9af1e00

Browse files
committed
Add extra traits for emscripten datatypes
1 parent ed23af1 commit 9af1e00

File tree

3 files changed

+188
-5
lines changed

3 files changed

+188
-5
lines changed

src/unix/notbsd/emscripten/align.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,35 @@ macro_rules! expand_align {
3232
repr(align(4)))]
3333
#[cfg_attr(target_pointer_width = "64",
3434
repr(align(8)))]
35-
#[allow(missing_debug_implementations)]
3635
pub struct pthread_cond_t {
3736
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
3837
}
3938
}
39+
40+
cfg_if! {
41+
if #[cfg(feature = "extra_traits")] {
42+
impl PartialEq for pthread_cond_t {
43+
fn eq(&self, other: &pthread_cond_t) -> bool {
44+
self.size
45+
.iter()
46+
.zip(other.size.iter())
47+
.all(|(a,b)| a == b)
48+
}
49+
}
50+
impl Eq for pthread_cond_t {}
51+
impl ::fmt::Debug for pthread_cond_t {
52+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
53+
f.debug_struct("pthread_cond_t")
54+
// FIXME: .field("size", &self.size)
55+
.finish()
56+
}
57+
}
58+
impl ::hash::Hash for pthread_cond_t {
59+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
60+
self.size.hash(state);
61+
}
62+
}
63+
}
64+
}
4065
}
4166
}

src/unix/notbsd/emscripten/mod.rs

Lines changed: 136 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ s! {
403403
}
404404

405405
s_no_extra_traits! {
406-
#[allow(missing_debug_implementations)]
407406
pub struct dirent {
408407
pub d_ino: ::ino_t,
409408
pub d_off: ::off_t,
@@ -412,7 +411,6 @@ s_no_extra_traits! {
412411
pub d_name: [::c_char; 256],
413412
}
414413

415-
#[allow(missing_debug_implementations)]
416414
pub struct dirent64 {
417415
pub d_ino: ::ino64_t,
418416
pub d_off: ::off64_t,
@@ -421,7 +419,6 @@ s_no_extra_traits! {
421419
pub d_name: [::c_char; 256],
422420
}
423421

424-
#[allow(missing_debug_implementations)]
425422
pub struct sysinfo {
426423
pub uptime: ::c_ulong,
427424
pub loads: [::c_ulong; 3],
@@ -440,6 +437,142 @@ s_no_extra_traits! {
440437
}
441438
}
442439

440+
cfg_if! {
441+
if #[cfg(feature = "extra_traits")] {
442+
impl PartialEq for dirent {
443+
fn eq(&self, other: &dirent) -> bool {
444+
self.d_ino == other.d_ino
445+
&& self.d_off == other.d_off
446+
&& self.d_reclen == other.d_reclen
447+
&& self.d_type == other.d_type
448+
&& self
449+
.d_name
450+
.iter()
451+
.zip(other.d_name.iter())
452+
.all(|(a,b)| a == b)
453+
}
454+
}
455+
impl Eq for dirent {}
456+
impl ::fmt::Debug for dirent {
457+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
458+
f.debug_struct("dirent")
459+
.field("d_ino", &self.d_ino)
460+
.field("d_off", &self.d_off)
461+
.field("d_reclen", &self.d_reclen)
462+
.field("d_type", &self.d_type)
463+
// FIXME: .field("d_name", &self.d_name)
464+
.finish()
465+
}
466+
}
467+
impl ::hash::Hash for dirent {
468+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
469+
self.d_ino.hash(state);
470+
self.d_off.hash(state);
471+
self.d_reclen.hash(state);
472+
self.d_type.hash(state);
473+
self.d_name.hash(state);
474+
}
475+
}
476+
477+
impl PartialEq for dirent64 {
478+
fn eq(&self, other: &dirent64) -> bool {
479+
self.d_ino == other.d_ino
480+
&& self.d_off == other.d_off
481+
&& self.d_reclen == other.d_reclen
482+
&& self.d_type == other.d_type
483+
&& self
484+
.d_name
485+
.iter()
486+
.zip(other.d_name.iter())
487+
.all(|(a,b)| a == b)
488+
}
489+
}
490+
impl Eq for dirent64 {}
491+
impl ::fmt::Debug for dirent64 {
492+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
493+
f.debug_struct("dirent64")
494+
.field("d_ino", &self.d_ino)
495+
.field("d_off", &self.d_off)
496+
.field("d_reclen", &self.d_reclen)
497+
.field("d_type", &self.d_type)
498+
// FIXME: .field("d_name", &self.d_name)
499+
.finish()
500+
}
501+
}
502+
impl ::hash::Hash for dirent64 {
503+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
504+
self.d_ino.hash(state);
505+
self.d_off.hash(state);
506+
self.d_reclen.hash(state);
507+
self.d_type.hash(state);
508+
self.d_name.hash(state);
509+
}
510+
}
511+
512+
impl PartialEq for sysinfo {
513+
fn eq(&self, other: &sysinfo) -> bool {
514+
self.uptime == other.uptime
515+
&& self.loads == other.loads
516+
&& self.totalram == other.totalram
517+
&& self.freeram == other.freeram
518+
&& self.sharedram == other.sharedram
519+
&& self.bufferram == other.bufferram
520+
&& self.totalswap == other.totalswap
521+
&& self.freeswap == other.freeswap
522+
&& self.procs == other.procs
523+
&& self.pad == other.pad
524+
&& self.totalhigh == other.totalhigh
525+
&& self.freehigh == other.freehigh
526+
&& self.mem_unit == other.mem_unit
527+
&& self
528+
.__reserved
529+
.iter()
530+
.zip(other.__reserved.iter())
531+
.all(|(a,b)| a == b)
532+
}
533+
}
534+
impl Eq for sysinfo {}
535+
impl ::fmt::Debug for sysinfo {
536+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
537+
f.debug_struct("sysinfo")
538+
.field("uptime", &self.uptime)
539+
.field("loads", &self.loads)
540+
.field("totalram", &self.totalram)
541+
.field("freeram", &self.freeram)
542+
.field("sharedram", &self.sharedram)
543+
.field("bufferram", &self.bufferram)
544+
.field("totalswap", &self.totalswap)
545+
.field("freeswap", &self.freeswap)
546+
.field("procs", &self.procs)
547+
.field("pad", &self.pad)
548+
.field("totalhigh", &self.totalhigh)
549+
.field("freehigh", &self.freehigh)
550+
.field("mem_unit", &self.mem_unit)
551+
// FIXME: .field("__reserved", &self.__reserved)
552+
.finish()
553+
}
554+
}
555+
impl ::hash::Hash for sysinfo {
556+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
557+
self.uptime.hash(state);
558+
self.loads.hash(state);
559+
self.totalram.hash(state);
560+
self.freeram.hash(state);
561+
self.sharedram.hash(state);
562+
self.bufferram.hash(state);
563+
self.totalswap.hash(state);
564+
self.freeswap.hash(state);
565+
self.procs.hash(state);
566+
self.pad.hash(state);
567+
self.totalhigh.hash(state);
568+
self.freehigh.hash(state);
569+
self.mem_unit.hash(state);
570+
self.__reserved.hash(state);
571+
}
572+
}
573+
}
574+
}
575+
443576
pub const ABDAY_1: ::nl_item = 0x20000;
444577
pub const ABDAY_2: ::nl_item = 0x20001;
445578
pub const ABDAY_3: ::nl_item = 0x20002;

src/unix/notbsd/emscripten/no_align.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,36 @@ macro_rules! expand_align {
2828
}
2929

3030
s_no_extra_traits! {
31-
#[allow(missing_debug_implementations)]
3231
pub struct pthread_cond_t {
3332
__align: [*const ::c_void; 0],
3433
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
3534
}
3635
}
36+
37+
cfg_if! {
38+
if #[cfg(feature = "extra_traits")] {
39+
impl PartialEq for pthread_cond_t {
40+
fn eq(&self, other: &pthread_cond_t) -> bool {
41+
self.size
42+
.iter()
43+
.zip(other.size.iter())
44+
.all(|(a,b)| a == b)
45+
}
46+
}
47+
impl Eq for pthread_cond_t {}
48+
impl ::fmt::Debug for pthread_cond_t {
49+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
50+
f.debug_struct("pthread_cond_t")
51+
// FIXME: .field("size", &self.size)
52+
.finish()
53+
}
54+
}
55+
impl ::hash::Hash for pthread_cond_t {
56+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
57+
self.size.hash(state);
58+
}
59+
}
60+
}
61+
}
3762
}
3863
}

0 commit comments

Comments
 (0)