Skip to content

Commit 600b9c8

Browse files
committed
Implement PartialEq,Eq for all types
1 parent 70284d7 commit 600b9c8

File tree

8 files changed

+428
-229
lines changed

8 files changed

+428
-229
lines changed

Cargo.lock

+36-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
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

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ 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 `PartialEq` and `Eq` can be
49+
enabled with the *extra_traits* feature (requires Rust 1.25 or newer):
50+
51+
```toml
52+
[dependencies]
53+
libc = { version = "0.2", features = ["extra_traits"] }
54+
```
55+
4756
## What is libc?
4857

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

src/macros.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ macro_rules! s {
3939
__item! {
4040
#[repr(C)]
4141
$(#[$attr])*
42+
#[derive(Clone, Copy)]
43+
#[cfg_attr(feature = "extra_traits", derive(Eq, PartialEq))]
4244
pub $t $i { $($field)* }
4345
}
44-
impl ::dox::Copy for $i {}
45-
impl ::dox::Clone for $i {
46-
fn clone(&self) -> $i { *self }
46+
)*)
47+
}
48+
49+
macro_rules! s_no_extra_traits {
50+
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
51+
__item! {
52+
#[repr(C)]
53+
$(#[$attr])*
54+
#[derive(Clone, Copy)]
55+
pub $t $i { $($field)* }
4756
}
4857
)*)
4958
}

0 commit comments

Comments
 (0)