Skip to content

Commit

Permalink
Merge pull request #342 from ethereum/rust-bindgen
Browse files Browse the repository at this point in the history
rust: support ParitalEq, Default, Hash on certain ffi types
  • Loading branch information
axic committed Jul 3, 2019
2 parents 5082181 + 98ad72e commit bc55131
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindings/rust/evmc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fn gen_bindings() {
.constified_enum("")
// generate Rust enums for each evmc enum
.rustified_enum("*")
// force deriving the Hash trait on basic types (address, bytes32)
.derive_hash(true)
.generate()
.expect("Unable to generate bindings");

Expand Down
27 changes: 27 additions & 0 deletions bindings/rust/evmc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,30 @@
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

// TODO: with bindgen's interface improving these may be moved to
// bindgen configuration

impl PartialEq for evmc_address {
fn eq(&self, other: &Self) -> bool {
self.bytes == other.bytes
}
}

impl PartialEq for evmc_bytes32 {
fn eq(&self, other: &Self) -> bool {
self.bytes == other.bytes
}
}

impl Default for evmc_address {
fn default() -> Self {
evmc_address { bytes: [0u8; 20] }
}
}

impl Default for evmc_bytes32 {
fn default() -> Self {
evmc_bytes32 { bytes: [0u8; 32] }
}
}

0 comments on commit bc55131

Please sign in to comment.