Skip to content

Commit 942f6ae

Browse files
committed
Auto merge of #1217 - Susurrus:rfc_2235, r=gnzlbg
RFC 2235 - Implement PartialEq,Eq,Hash,Debug for all types First pass at implementing [RFC2235](https://github.com/rust-lang/rfcs/blob/master/text/2235-libc-struct-traits.md). I just started with `PartialEq`/`Eq` and tested locally on my x64 Linux system. Definitely going to run into other types for other platforms that need this treatment, but thought I'd start small. Open question is whether this should also rely on the `align` feature, which should improve which types can be auto-derived versus manually implemented (as it removed a lot of odd-sized padding arrays). My first pass here doesn't do that, but I might test it out to see if it does simplify quite a few structs. I think it might also be nice to have as it makes it easier for contributors to add new structs. Part of rust-lang/rust#57715
2 parents 1f63b26 + e33f760 commit 942f6ae

File tree

37 files changed

+2150
-763
lines changed

37 files changed

+2150
-763
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target
22
Cargo.lock
33
*~
4+
style

Cargo.lock

Lines changed: 0 additions & 340 deletions
This file was deleted.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ default = ["use_std"]
2727
use_std = []
2828
align = []
2929
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
30+
extra_traits = ["align"]
3031

3132
[workspace]
3233
members = ["libc-test"]

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ activate the *align* feature. This requires Rust 1.25 or newer:
4444
libc = { version = "0.2", features = ["align"] }
4545
```
4646

47+
All structs implemented by the libc crate have the `Copy` and `Clone` traits
48+
implemented for them. The additional traits of `Debug, `Eq`, `Hash`, and
49+
`PartialEq` can be enabled with the *extra_traits* feature (requires Rust 1.25
50+
or newer):
51+
52+
```toml
53+
[dependencies]
54+
libc = { version = "0.2", features = ["extra_traits"] }
55+
```
56+
4757
## What is libc?
4858

4959
The primary purpose of this crate is to provide all of the definitions necessary

ci/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ fi
9696
if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
9797
cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}"
9898
fi
99+
# Test the `extra_traits` feature if this is building on Rust >= 1.25
100+
if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
101+
cargo test $opt --features extra_traits --manifest-path libc-test/Cargo.toml --target "${TARGET}"
102+
fi
99103
exec cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"

libc-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ctest = "0.2.8"
1515
default = [ "use_std" ]
1616
use_std = [ "libc/use_std" ]
1717
align = [ "libc/align" ]
18+
extra_traits = [ "libc/extra_traits" ]
1819

1920
[[test]]
2021
name = "main"

0 commit comments

Comments
 (0)