Add extra traits for freebsd datatypes

This commit is contained in:
Bryant Mairs 2019-02-22 19:33:17 -08:00
parent 6061ec3e9c
commit c3ddeaeed3
2 changed files with 261 additions and 5 deletions

View File

@ -141,7 +141,6 @@ s! {
}
s_no_extra_traits! {
#[allow(missing_debug_implementations)]
pub struct utmpx {
pub ut_type: ::c_short,
pub ut_tv: ::timeval,
@ -153,7 +152,6 @@ s_no_extra_traits! {
pub __ut_spare: [::c_char; 64],
}
#[allow(missing_debug_implementations)]
pub struct dirent {
pub d_fileno: u32,
pub d_reclen: u16,
@ -162,7 +160,6 @@ s_no_extra_traits! {
pub d_name: [::c_char; 256],
}
#[allow(missing_debug_implementations)]
pub struct statfs {
pub f_version: ::uint32_t,
pub f_type: ::uint32_t,
@ -188,7 +185,6 @@ s_no_extra_traits! {
pub f_mntonname: [::c_char; 88],
}
#[allow(missing_debug_implementations)]
pub struct sockaddr_dl {
pub sdl_len: ::c_uchar,
pub sdl_family: ::c_uchar,
@ -201,6 +197,228 @@ s_no_extra_traits! {
}
}
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for utmpx {
fn eq(&self, other: &utmpx) -> bool {
self.ut_type == other.ut_type
&& self.ut_tv == other.ut_tv
&& self.ut_id == other.ut_id
&& self.ut_pid == other.ut_pid
&& self.ut_user == other.ut_user
&& self.ut_line == other.ut_line
&& self
.ut_host
.iter()
.zip(other.ut_host.iter())
.all(|(a,b)| a == b)
&& self
.__ut_spare
.iter()
.zip(other.__ut_spare.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for utmpx {}
impl ::fmt::Debug for utmpx {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("utmpx")
.field("ut_type", &self.ut_type)
.field("ut_tv", &self.ut_tv)
.field("ut_id", &self.ut_id)
.field("ut_pid", &self.ut_pid)
.field("ut_user", &self.ut_user)
.field("ut_line", &self.ut_line)
// FIXME: .field("ut_host", &self.ut_host)
// FIXME: .field("__ut_spare", &self.__ut_spare)
.finish()
}
}
impl ::hash::Hash for utmpx {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ut_type.hash(state);
self.ut_tv.hash(state);
self.ut_id.hash(state);
self.ut_pid.hash(state);
self.ut_user.hash(state);
self.ut_line.hash(state);
self.ut_host.hash(state);
self.__ut_spare.hash(state);
}
}
impl PartialEq for dirent {
fn eq(&self, other: &dirent) -> bool {
self.d_fileno == other.d_fileno
&& self.d_reclen == other.d_reclen
&& self.d_type == other.d_type
&& self.d_namlen == other.d_namlen
&& self
.d_name
.iter()
.zip(other.d_name.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for dirent {}
impl ::fmt::Debug for dirent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("dirent")
.field("d_fileno", &self.d_fileno)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
.field("d_namlen", &self.d_namlen)
// FIXME: .field("d_name", &self.d_name)
.finish()
}
}
impl ::hash::Hash for dirent {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.d_fileno.hash(state);
self.d_reclen.hash(state);
self.d_type.hash(state);
self.d_namlen.hash(state);
self.d_name.hash(state);
}
}
impl PartialEq for statfs {
fn eq(&self, other: &statfs) -> bool {
self.f_version == other.f_version
&& self.f_type == other.f_type
&& self.f_flags == other.f_flags
&& self.f_bsize == other.f_bsize
&& self.f_iosize == other.f_iosize
&& self.f_blocks == other.f_blocks
&& self.f_bfree == other.f_bfree
&& self.f_bavail == other.f_bavail
&& self.f_files == other.f_files
&& self.f_ffree == other.f_ffree
&& self.f_syncwrites == other.f_syncwrites
&& self.f_asyncwrites == other.f_asyncwrites
&& self.f_syncreads == other.f_syncreads
&& self.f_asyncreads == other.f_asyncreads
&& self.f_spare == other.f_spare
&& self.f_namemax == other.f_namemax
&& self.f_owner == other.f_owner
&& self.f_fsid == other.f_fsid
&& self
.f_charspare
.iter()
.zip(other.f_charspare.iter())
.all(|(a,b)| a == b)
&& self.f_fstypename == other.f_fstypename
&& self
.f_mntfromname
.iter()
.zip(other.f_mntfromname.iter())
.all(|(a,b)| a == b)
&& self
.f_mntonname
.iter()
.zip(other.f_mntonname.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for statfs {}
impl ::fmt::Debug for statfs {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("statfs")
.field("f_bsize", &self.f_bsize)
.field("f_iosize", &self.f_iosize)
.field("f_blocks", &self.f_blocks)
.field("f_bfree", &self.f_bfree)
.field("f_bavail", &self.f_bavail)
.field("f_files", &self.f_files)
.field("f_ffree", &self.f_ffree)
.field("f_syncwrites", &self.f_syncwrites)
.field("f_asyncwrites", &self.f_asyncwrites)
.field("f_syncreads", &self.f_syncreads)
.field("f_asyncreads", &self.f_asyncreads)
.field("f_spare", &self.f_spare)
.field("f_namemax", &self.f_namemax)
.field("f_owner", &self.f_owner)
.field("f_fsid", &self.f_fsid)
// FIXME: .field("f_charspare", &self.f_charspare)
.field("f_fstypename", &self.f_fstypename)
// FIXME: .field("f_mntfromname", &self.f_mntfromname)
// FIXME: .field("f_mntonname", &self.f_mntonname)
.finish()
}
}
impl ::hash::Hash for statfs {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.f_version.hash(state);
self.f_type.hash(state);
self.f_flags.hash(state);
self.f_bsize.hash(state);
self.f_iosize.hash(state);
self.f_blocks.hash(state);
self.f_bfree.hash(state);
self.f_bavail.hash(state);
self.f_files.hash(state);
self.f_ffree.hash(state);
self.f_syncwrites.hash(state);
self.f_asyncwrites.hash(state);
self.f_syncreads.hash(state);
self.f_asyncreads.hash(state);
self.f_spare.hash(state);
self.f_namemax.hash(state);
self.f_owner.hash(state);
self.f_fsid.hash(state);
self.f_charspare.hash(state);
self.f_fstypename.hash(state);
self.f_mntfromname.hash(state);
self.f_mntonname.hash(state);
}
}
impl PartialEq for sockaddr_dl {
fn eq(&self, other: &sockaddr_dl) -> bool {
self.sdl_len == other.sdl_len
&& self.sdl_family == other.sdl_family
&& self.sdl_index == other.sdl_index
&& self.sdl_type == other.sdl_type
&& self.sdl_nlen == other.sdl_nlen
&& self.sdl_alen == other.sdl_alen
&& self.sdl_slen == other.sdl_slen
&& self
.sdl_data
.iter()
.zip(other.sdl_data.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for sockaddr_dl {}
impl ::fmt::Debug for sockaddr_dl {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_dl")
.field("sdl_len", &self.sdl_len)
.field("sdl_family", &self.sdl_family)
.field("sdl_index", &self.sdl_index)
.field("sdl_type", &self.sdl_type)
.field("sdl_nlen", &self.sdl_nlen)
.field("sdl_alen", &self.sdl_alen)
.field("sdl_slen", &self.sdl_slen)
// FIXME: .field("sdl_data", &self.sdl_data)
.finish()
}
}
impl ::hash::Hash for sockaddr_dl {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.sdl_len.hash(state);
self.sdl_family.hash(state);
self.sdl_index.hash(state);
self.sdl_type.hash(state);
self.sdl_nlen.hash(state);
self.sdl_alen.hash(state);
self.sdl_slen.hash(state);
self.sdl_data.hash(state);
}
}
}
}
pub const SIGEV_THREAD_ID: ::c_int = 4;
pub const EXTATTR_NAMESPACE_EMPTY: ::c_int = 0;

View File

@ -189,7 +189,6 @@ s! {
}
s_no_extra_traits! {
#[allow(missing_debug_implementations)]
pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: ::sa_family_t,
@ -199,6 +198,45 @@ s_no_extra_traits! {
}
}
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for sockaddr_storage {
fn eq(&self, other: &sockaddr_storage) -> bool {
self.ss_len == other.ss_len
&& self.ss_family == other.ss_family
&& self.__ss_pad1 == other.__ss_pad1
&& self.__ss_align == other.__ss_align
&& self
.__ss_pad2
.iter()
.zip(other.__ss_pad2.iter())
.all(|(a, b)| a == b)
}
}
impl Eq for sockaddr_storage {}
impl ::fmt::Debug for sockaddr_storage {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_storage")
.field("ss_len", &self.ss_len)
.field("ss_family", &self.ss_family)
.field("__ss_pad1", &self.__ss_pad1)
.field("__ss_align", &self.__ss_align)
// FIXME: .field("__ss_pad2", &self.__ss_pad2)
.finish()
}
}
impl ::hash::Hash for sockaddr_storage {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ss_len.hash(state);
self.ss_family.hash(state);
self.__ss_pad1.hash(state);
self.__ss_align.hash(state);
self.__ss_pad2.hash(state);
}
}
}
}
pub const AIO_LISTIO_MAX: ::c_int = 16;
pub const AIO_CANCELED: ::c_int = 1;
pub const AIO_NOTCANCELED: ::c_int = 2;