Skip to content

Commit

Permalink
Implement PartialEq,Eq for all types
Browse files Browse the repository at this point in the history
  • Loading branch information
Susurrus committed Jan 22, 2019
1 parent 70284d7 commit 600b9c8
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 229 deletions.
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ default = ["use_std"]
use_std = []
align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
extra_traits = ["align"]

[workspace]
members = ["libc-test"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ activate the *align* feature. This requires Rust 1.25 or newer:
libc = { version = "0.2", features = ["align"] }
```

All structs implemented by the libc crate have the `Copy` and `Clone` traits
implemented for them. The additional traits of `PartialEq` and `Eq` can be
enabled with the *extra_traits* feature (requires Rust 1.25 or newer):

```toml
[dependencies]
libc = { version = "0.2", features = ["extra_traits"] }
```

## What is libc?

The primary purpose of this crate is to provide all of the definitions necessary
Expand Down
15 changes: 12 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ macro_rules! s {
__item! {
#[repr(C)]
$(#[$attr])*
#[derive(Clone, Copy)]
#[cfg_attr(feature = "extra_traits", derive(Eq, PartialEq))]
pub $t $i { $($field)* }
}
impl ::dox::Copy for $i {}
impl ::dox::Clone for $i {
fn clone(&self) -> $i { *self }
)*)
}

macro_rules! s_no_extra_traits {
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
__item! {
#[repr(C)]
$(#[$attr])*
#[derive(Clone, Copy)]
pub $t $i { $($field)* }
}
)*)
}
Expand Down
Loading

0 comments on commit 600b9c8

Please sign in to comment.