Skip to content

Commit 3f55d23

Browse files
committed
Add extra traits for dragonfly datatypes
1 parent 64ab364 commit 3f55d23

File tree

1 file changed

+176
-3
lines changed
  • src/unix/bsd/freebsdlike/dragonfly

1 file changed

+176
-3
lines changed

src/unix/bsd/freebsdlike/dragonfly/mod.rs

+176-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ s! {
177177
}
178178

179179
s_no_extra_traits! {
180-
#[allow(missing_debug_implementations)]
181180
pub struct utmpx {
182181
pub ut_name: [::c_char; 32],
183182
pub ut_id: [::c_char; 4],
@@ -195,7 +194,6 @@ s_no_extra_traits! {
195194
pub ut_unused2: [u8; 16],
196195
}
197196

198-
#[allow(missing_debug_implementations)]
199197
pub struct dirent {
200198
pub d_fileno: ::ino_t,
201199
pub d_namlen: u16,
@@ -205,7 +203,6 @@ s_no_extra_traits! {
205203
pub d_name: [::c_char; 256],
206204
}
207205

208-
#[allow(missing_debug_implementations)]
209206
pub struct statfs {
210207
pub f_bsize: ::c_long,
211208
pub f_iosize: ::c_long,
@@ -228,6 +225,182 @@ s_no_extra_traits! {
228225
}
229226
}
230227

228+
cfg_if! {
229+
if #[cfg(feature = "extra_traits")] {
230+
impl PartialEq for utmpx {
231+
fn eq(&self, other: &utmpx) -> bool {
232+
self.ut_name == other.ut_name
233+
&& self.ut_id == other.ut_id
234+
&& self.ut_line == other.ut_line
235+
&& self
236+
.ut_host
237+
.iter()
238+
.zip(other.ut_host.iter())
239+
.all(|(a,b)| a == b)
240+
&& self.ut_unused == other.ut_unused
241+
&& self.ut_session == other.ut_session
242+
&& self.ut_type == other.ut_type
243+
&& self.ut_pid == other.ut_pid
244+
&& self.ut_exit == other.ut_exit
245+
&& self.ut_ss == other.ut_ss
246+
&& self.ut_tv == other.ut_tv
247+
&& self.ut_unused2 == other.ut_unused2
248+
}
249+
}
250+
impl Eq for utmpx {}
251+
impl ::fmt::Debug for utmpx {
252+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
253+
f.debug_struct("utmpx")
254+
.field("ut_name", &self.ut_name)
255+
.field("ut_id", &self.ut_id)
256+
.field("ut_line", &self.ut_line)
257+
// FIXME: .field("ut_host", &self.ut_host)
258+
.field("ut_unused", &self.ut_unused)
259+
.field("ut_session", &self.ut_session)
260+
.field("ut_type", &self.ut_type)
261+
.field("ut_pid", &self.ut_pid)
262+
.field("ut_exit", &self.ut_exit)
263+
.field("ut_ss", &self.ut_ss)
264+
.field("ut_tv", &self.ut_tv)
265+
.field("ut_unused2", &self.ut_unused2)
266+
.finish()
267+
}
268+
}
269+
impl ::hash::Hash for utmpx {
270+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
271+
self.ut_name.hash(state);
272+
self.ut_id.hash(state);
273+
self.ut_line.hash(state);
274+
self.ut_host.hash(state);
275+
self.ut_unused.hash(state);
276+
self.ut_session.hash(state);
277+
self.ut_type.hash(state);
278+
self.ut_pid.hash(state);
279+
self.ut_exit.hash(state);
280+
self.ut_ss.hash(state);
281+
self.ut_tv.hash(state);
282+
self.ut_unused2.hash(state);
283+
}
284+
}
285+
286+
impl PartialEq for dirent {
287+
fn eq(&self, other: &dirent) -> bool {
288+
self.d_fileno == other.d_fileno
289+
&& self.d_namlen == other.d_namlen
290+
&& self.d_type == other.d_type
291+
// Ignore __unused1
292+
// Ignore __unused2
293+
&& self
294+
.d_name
295+
.iter()
296+
.zip(other.d_name.iter())
297+
.all(|(a,b)| a == b)
298+
}
299+
}
300+
impl Eq for dirent {}
301+
impl ::fmt::Debug for dirent {
302+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
303+
f.debug_struct("dirent")
304+
.field("d_fileno", &self.d_fileno)
305+
.field("d_namlen", &self.d_namlen)
306+
.field("d_type", &self.d_type)
307+
// Ignore __unused1
308+
// Ignore __unused2
309+
// FIXME: .field("d_name", &self.d_name)
310+
.finish()
311+
}
312+
}
313+
impl ::hash::Hash for dirent {
314+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
315+
self.d_fileno.hash(state);
316+
self.d_namlen.hash(state);
317+
self.d_type.hash(state);
318+
// Ignore __unused1
319+
// Ignore __unused2
320+
self.d_name.hash(state);
321+
}
322+
}
323+
324+
impl PartialEq for statfs {
325+
fn eq(&self, other: &statfs) -> bool {
326+
self.f_bsize == other.f_bsize
327+
&& self.f_iosize == other.f_iosize
328+
&& self.f_blocks == other.f_blocks
329+
&& self.f_bfree == other.f_bfree
330+
&& self.f_bavail == other.f_bavail
331+
&& self.f_files == other.f_files
332+
&& self.f_ffree == other.f_ffree
333+
&& self.f_fsid == other.f_fsid
334+
&& self.f_owner == other.f_owner
335+
&& self.f_type == other.f_type
336+
&& self.f_flags == other.f_flags
337+
&& self.f_syncwrites == other.f_syncwrites
338+
&& self.f_asyncwrites == other.f_asyncwrites
339+
&& self.f_fstypename == other.f_fstypename
340+
&& self
341+
.f_mntonname
342+
.iter()
343+
.zip(other.f_mntonname.iter())
344+
.all(|(a,b)| a == b)
345+
&& self.f_syncreads == other.f_syncreads
346+
&& self.f_asyncreads == other.f_asyncreads
347+
&& self
348+
.f_mntfromname
349+
.iter()
350+
.zip(other.f_mntfromname.iter())
351+
.all(|(a,b)| a == b)
352+
&& self.f_reserved == other.f_reserved
353+
}
354+
}
355+
impl Eq for statfs {}
356+
impl ::fmt::Debug for statfs {
357+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
358+
f.debug_struct("statfs")
359+
.field("f_bsize", &self.f_bsize)
360+
.field("f_iosize", &self.f_iosize)
361+
.field("f_blocks", &self.f_blocks)
362+
.field("f_bfree", &self.f_bfree)
363+
.field("f_bavail", &self.f_bavail)
364+
.field("f_files", &self.f_files)
365+
.field("f_ffree", &self.f_ffree)
366+
.field("f_fsid", &self.f_fsid)
367+
.field("f_owner", &self.f_owner)
368+
.field("f_type", &self.f_type)
369+
.field("f_flags", &self.f_flags)
370+
.field("f_syncwrites", &self.f_syncwrites)
371+
.field("f_asyncwrites", &self.f_asyncwrites)
372+
// FIXME: .field("f_mntonname", &self.f_mntonname)
373+
.field("f_syncreads", &self.f_syncreads)
374+
.field("f_asyncreads", &self.f_asyncreads)
375+
// FIXME: .field("f_mntfromname", &self.f_mntfromname)
376+
.finish()
377+
}
378+
}
379+
impl ::hash::Hash for statfs {
380+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
381+
self.f_bsize.hash(state);
382+
self.f_iosize.hash(state);
383+
self.f_blocks.hash(state);
384+
self.f_bfree.hash(state);
385+
self.f_bavail.hash(state);
386+
self.f_files.hash(state);
387+
self.f_ffree.hash(state);
388+
self.f_fsid.hash(state);
389+
self.f_owner.hash(state);
390+
self.f_type.hash(state);
391+
self.f_flags.hash(state);
392+
self.f_syncwrites.hash(state);
393+
self.f_asyncwrites.hash(state);
394+
self.f_fstypename.hash(state);
395+
self.f_mntonname.hash(state);
396+
self.f_syncreads.hash(state);
397+
self.f_asyncreads.hash(state);
398+
self.f_mntfromname.hash(state);
399+
}
400+
}
401+
}
402+
}
403+
231404
pub const RAND_MAX: ::c_int = 0x7fff_ffff;
232405
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
233406
pub const SIGSTKSZ: ::size_t = 40960;

0 commit comments

Comments
 (0)