Merge pull request #342 from ethereum/rust-bindgen

rust: support ParitalEq, Default, Hash on certain ffi types
This commit is contained in:
Alex Beregszaszi 2019-07-03 18:29:04 +01:00 committed by GitHub
commit bc551318e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -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");

View File

@ -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] }
}
}