- Feature Name:
libc_struct_traits
- Start Date: 2017-12-05
- RFC PR: rust-lang/rfcs#2235
- Rust Issue: rust-lang/rust#57715
Summary
Expand the traits implementedlibc
crate to include Debug
, Eq
, Hash
, and PartialEq
.
Motivation
This will allowlibc
structs.
For many of these traits, it is trivial for downstream crates to implementnix
crate offers the TimeSpec
wrapper type around the timespec
struct.Eq
through comparing
Unfortunately there are a great many structsnix
are dqblk
, utsname
, and statvfs
. These structsnix
aims to support as many platforms as libc
does, this variation makes implementing
Guide-level explanation
Add an extra_traits
feature to the libc
library that enables Debug
, Eq
, Hash
, and PartialEq
implementations
Reference-level explanation
The Debug
, Eq
/PartialEq
, and Hash
traits will be addeds!
macro in src/macros.rs
if the correspondinglibc
as of bbda50d20937e570df5ec857eea0e2a098e76b2d
on x86_64-unknown-linux-gnu
these many structs
Debug
- 17Eq
/PartialEq
- 46Hash
- 17
Drawbacks
While most structslibc
.
This extra trait will increase the testing requirements for libc
.
Rationale and alternatives代わりのもの、選択肢
Adding
Always enabled with no feature flags
This was regarded as unsuitable because it increaseslibc
was tested at commit bbda50d20937e570df5ec857eea0e2a098e76b2d
with modifications to add derives for the traits discussed here under the extra_traits
feature (with no other features). Some types failed to have these traits derived because of specific
Build arguments | Time |
---|---|
cargo clean && cargo build --no-default-features | 0.84s |
cargo clean && cargo build --no-default-features --features extra_traits | 2.17s |
cargo clean && cargo build --no-default-features --release | 0.64s |
cargo clean && cargo build --no-default-features --release --features extra_traits | 1.80s |
cargo clean && cargo build --no-default-features --features use_std | 1.14s |
cargo clean && cargo build --no-default-features --features use_std,extra_traits | 2.34s |
cargo clean && cargo build --no-default-features --release --features use_std | 0.66s |
cargo clean && cargo build --no-default-features --release --features use_std,extra_traits | 1.94s |
Default-on feature
For crates that are more than one level above libc
in the dependency
Multiple複数の feature flags
Instead of having a singleextra_traits
feature, have it and feature flags for each trait individually
trait_debug
- EnablesDebug
for all structs構造、構造体trait_eg
- EnablesEq
andPartialEq
for all structs構造、構造体trait_hash
- EnablesHash
for all structs構造、構造体extra_traits
- Enables all of the above through dependent features
This change should reduce compilation times when not all traits are desired. The downsides are that it complicates CI. It can be added