Skip to content

Commit c3ddeae

Browse files
committed
Add extra traits for freebsd datatypes
1 parent 6061ec3 commit c3ddeae

File tree

2 files changed

+261
-5
lines changed

2 files changed

+261
-5
lines changed

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

+222-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ s! {
141141
}
142142

143143
s_no_extra_traits! {
144-
#[allow(missing_debug_implementations)]
145144
pub struct utmpx {
146145
pub ut_type: ::c_short,
147146
pub ut_tv: ::timeval,
@@ -153,7 +152,6 @@ s_no_extra_traits! {
153152
pub __ut_spare: [::c_char; 64],
154153
}
155154

156-
#[allow(missing_debug_implementations)]
157155
pub struct dirent {
158156
pub d_fileno: u32,
159157
pub d_reclen: u16,
@@ -162,7 +160,6 @@ s_no_extra_traits! {
162160
pub d_name: [::c_char; 256],
163161
}
164162

165-
#[allow(missing_debug_implementations)]
166163
pub struct statfs {
167164
pub f_version: ::uint32_t,
168165
pub f_type: ::uint32_t,
@@ -188,7 +185,6 @@ s_no_extra_traits! {
188185
pub f_mntonname: [::c_char; 88],
189186
}
190187

191-
#[allow(missing_debug_implementations)]
192188
pub struct sockaddr_dl {
193189
pub sdl_len: ::c_uchar,
194190
pub sdl_family: ::c_uchar,
@@ -201,6 +197,228 @@ s_no_extra_traits! {
201197
}
202198
}
203199

200+
cfg_if! {
201+
if #[cfg(feature = "extra_traits")] {
202+
impl PartialEq for utmpx {
203+
fn eq(&self, other: &utmpx) -> bool {
204+
self.ut_type == other.ut_type
205+
&& self.ut_tv == other.ut_tv
206+
&& self.ut_id == other.ut_id
207+
&& self.ut_pid == other.ut_pid
208+
&& self.ut_user == other.ut_user
209+
&& self.ut_line == other.ut_line
210+
&& self
211+
.ut_host
212+
.iter()
213+
.zip(other.ut_host.iter())
214+
.all(|(a,b)| a == b)
215+
&& self
216+
.__ut_spare
217+
.iter()
218+
.zip(other.__ut_spare.iter())
219+
.all(|(a,b)| a == b)
220+
}
221+
}
222+
impl Eq for utmpx {}
223+
impl ::fmt::Debug for utmpx {
224+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
225+
f.debug_struct("utmpx")
226+
.field("ut_type", &self.ut_type)
227+
.field("ut_tv", &self.ut_tv)
228+
.field("ut_id", &self.ut_id)
229+
.field("ut_pid", &self.ut_pid)
230+
.field("ut_user", &self.ut_user)
231+
.field("ut_line", &self.ut_line)
232+
// FIXME: .field("ut_host", &self.ut_host)
233+
// FIXME: .field("__ut_spare", &self.__ut_spare)
234+
.finish()
235+
}
236+
}
237+
impl ::hash::Hash for utmpx {
238+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
239+
self.ut_type.hash(state);
240+
self.ut_tv.hash(state);
241+
self.ut_id.hash(state);
242+
self.ut_pid.hash(state);
243+
self.ut_user.hash(state);
244+
self.ut_line.hash(state);
245+
self.ut_host.hash(state);
246+
self.__ut_spare.hash(state);
247+
}
248+
}
249+
250+
impl PartialEq for dirent {
251+
fn eq(&self, other: &dirent) -> bool {
252+
self.d_fileno == other.d_fileno
253+
&& self.d_reclen == other.d_reclen
254+
&& self.d_type == other.d_type
255+
&& self.d_namlen == other.d_namlen
256+
&& self
257+
.d_name
258+
.iter()
259+
.zip(other.d_name.iter())
260+
.all(|(a,b)| a == b)
261+
}
262+
}
263+
impl Eq for dirent {}
264+
impl ::fmt::Debug for dirent {
265+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
266+
f.debug_struct("dirent")
267+
.field("d_fileno", &self.d_fileno)
268+
.field("d_reclen", &self.d_reclen)
269+
.field("d_type", &self.d_type)
270+
.field("d_namlen", &self.d_namlen)
271+
// FIXME: .field("d_name", &self.d_name)
272+
.finish()
273+
}
274+
}
275+
impl ::hash::Hash for dirent {
276+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
277+
self.d_fileno.hash(state);
278+
self.d_reclen.hash(state);
279+
self.d_type.hash(state);
280+
self.d_namlen.hash(state);
281+
self.d_name.hash(state);
282+
}
283+
}
284+
285+
impl PartialEq for statfs {
286+
fn eq(&self, other: &statfs) -> bool {
287+
self.f_version == other.f_version
288+
&& self.f_type == other.f_type
289+
&& self.f_flags == other.f_flags
290+
&& self.f_bsize == other.f_bsize
291+
&& self.f_iosize == other.f_iosize
292+
&& self.f_blocks == other.f_blocks
293+
&& self.f_bfree == other.f_bfree
294+
&& self.f_bavail == other.f_bavail
295+
&& self.f_files == other.f_files
296+
&& self.f_ffree == other.f_ffree
297+
&& self.f_syncwrites == other.f_syncwrites
298+
&& self.f_asyncwrites == other.f_asyncwrites
299+
&& self.f_syncreads == other.f_syncreads
300+
&& self.f_asyncreads == other.f_asyncreads
301+
&& self.f_spare == other.f_spare
302+
&& self.f_namemax == other.f_namemax
303+
&& self.f_owner == other.f_owner
304+
&& self.f_fsid == other.f_fsid
305+
&& self
306+
.f_charspare
307+
.iter()
308+
.zip(other.f_charspare.iter())
309+
.all(|(a,b)| a == b)
310+
&& self.f_fstypename == other.f_fstypename
311+
&& self
312+
.f_mntfromname
313+
.iter()
314+
.zip(other.f_mntfromname.iter())
315+
.all(|(a,b)| a == b)
316+
&& self
317+
.f_mntonname
318+
.iter()
319+
.zip(other.f_mntonname.iter())
320+
.all(|(a,b)| a == b)
321+
}
322+
}
323+
impl Eq for statfs {}
324+
impl ::fmt::Debug for statfs {
325+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
326+
f.debug_struct("statfs")
327+
.field("f_bsize", &self.f_bsize)
328+
.field("f_iosize", &self.f_iosize)
329+
.field("f_blocks", &self.f_blocks)
330+
.field("f_bfree", &self.f_bfree)
331+
.field("f_bavail", &self.f_bavail)
332+
.field("f_files", &self.f_files)
333+
.field("f_ffree", &self.f_ffree)
334+
.field("f_syncwrites", &self.f_syncwrites)
335+
.field("f_asyncwrites", &self.f_asyncwrites)
336+
.field("f_syncreads", &self.f_syncreads)
337+
.field("f_asyncreads", &self.f_asyncreads)
338+
.field("f_spare", &self.f_spare)
339+
.field("f_namemax", &self.f_namemax)
340+
.field("f_owner", &self.f_owner)
341+
.field("f_fsid", &self.f_fsid)
342+
// FIXME: .field("f_charspare", &self.f_charspare)
343+
.field("f_fstypename", &self.f_fstypename)
344+
// FIXME: .field("f_mntfromname", &self.f_mntfromname)
345+
// FIXME: .field("f_mntonname", &self.f_mntonname)
346+
.finish()
347+
}
348+
}
349+
impl ::hash::Hash for statfs {
350+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
351+
self.f_version.hash(state);
352+
self.f_type.hash(state);
353+
self.f_flags.hash(state);
354+
self.f_bsize.hash(state);
355+
self.f_iosize.hash(state);
356+
self.f_blocks.hash(state);
357+
self.f_bfree.hash(state);
358+
self.f_bavail.hash(state);
359+
self.f_files.hash(state);
360+
self.f_ffree.hash(state);
361+
self.f_syncwrites.hash(state);
362+
self.f_asyncwrites.hash(state);
363+
self.f_syncreads.hash(state);
364+
self.f_asyncreads.hash(state);
365+
self.f_spare.hash(state);
366+
self.f_namemax.hash(state);
367+
self.f_owner.hash(state);
368+
self.f_fsid.hash(state);
369+
self.f_charspare.hash(state);
370+
self.f_fstypename.hash(state);
371+
self.f_mntfromname.hash(state);
372+
self.f_mntonname.hash(state);
373+
}
374+
}
375+
376+
impl PartialEq for sockaddr_dl {
377+
fn eq(&self, other: &sockaddr_dl) -> bool {
378+
self.sdl_len == other.sdl_len
379+
&& self.sdl_family == other.sdl_family
380+
&& self.sdl_index == other.sdl_index
381+
&& self.sdl_type == other.sdl_type
382+
&& self.sdl_nlen == other.sdl_nlen
383+
&& self.sdl_alen == other.sdl_alen
384+
&& self.sdl_slen == other.sdl_slen
385+
&& self
386+
.sdl_data
387+
.iter()
388+
.zip(other.sdl_data.iter())
389+
.all(|(a,b)| a == b)
390+
}
391+
}
392+
impl Eq for sockaddr_dl {}
393+
impl ::fmt::Debug for sockaddr_dl {
394+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
395+
f.debug_struct("sockaddr_dl")
396+
.field("sdl_len", &self.sdl_len)
397+
.field("sdl_family", &self.sdl_family)
398+
.field("sdl_index", &self.sdl_index)
399+
.field("sdl_type", &self.sdl_type)
400+
.field("sdl_nlen", &self.sdl_nlen)
401+
.field("sdl_alen", &self.sdl_alen)
402+
.field("sdl_slen", &self.sdl_slen)
403+
// FIXME: .field("sdl_data", &self.sdl_data)
404+
.finish()
405+
}
406+
}
407+
impl ::hash::Hash for sockaddr_dl {
408+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
409+
self.sdl_len.hash(state);
410+
self.sdl_family.hash(state);
411+
self.sdl_index.hash(state);
412+
self.sdl_type.hash(state);
413+
self.sdl_nlen.hash(state);
414+
self.sdl_alen.hash(state);
415+
self.sdl_slen.hash(state);
416+
self.sdl_data.hash(state);
417+
}
418+
}
419+
}
420+
}
421+
204422
pub const SIGEV_THREAD_ID: ::c_int = 4;
205423

206424
pub const EXTATTR_NAMESPACE_EMPTY: ::c_int = 0;

src/unix/bsd/freebsdlike/mod.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ s! {
189189
}
190190

191191
s_no_extra_traits! {
192-
#[allow(missing_debug_implementations)]
193192
pub struct sockaddr_storage {
194193
pub ss_len: u8,
195194
pub ss_family: ::sa_family_t,
@@ -199,6 +198,45 @@ s_no_extra_traits! {
199198
}
200199
}
201200

201+
cfg_if! {
202+
if #[cfg(feature = "extra_traits")] {
203+
impl PartialEq for sockaddr_storage {
204+
fn eq(&self, other: &sockaddr_storage) -> bool {
205+
self.ss_len == other.ss_len
206+
&& self.ss_family == other.ss_family
207+
&& self.__ss_pad1 == other.__ss_pad1
208+
&& self.__ss_align == other.__ss_align
209+
&& self
210+
.__ss_pad2
211+
.iter()
212+
.zip(other.__ss_pad2.iter())
213+
.all(|(a, b)| a == b)
214+
}
215+
}
216+
impl Eq for sockaddr_storage {}
217+
impl ::fmt::Debug for sockaddr_storage {
218+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
219+
f.debug_struct("sockaddr_storage")
220+
.field("ss_len", &self.ss_len)
221+
.field("ss_family", &self.ss_family)
222+
.field("__ss_pad1", &self.__ss_pad1)
223+
.field("__ss_align", &self.__ss_align)
224+
// FIXME: .field("__ss_pad2", &self.__ss_pad2)
225+
.finish()
226+
}
227+
}
228+
impl ::hash::Hash for sockaddr_storage {
229+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
230+
self.ss_len.hash(state);
231+
self.ss_family.hash(state);
232+
self.__ss_pad1.hash(state);
233+
self.__ss_align.hash(state);
234+
self.__ss_pad2.hash(state);
235+
}
236+
}
237+
}
238+
}
239+
202240
pub const AIO_LISTIO_MAX: ::c_int = 16;
203241
pub const AIO_CANCELED: ::c_int = 1;
204242
pub const AIO_NOTCANCELED: ::c_int = 2;

0 commit comments

Comments
 (0)