diff options
author | Robin Krahl <me@robin-krahl.de> | 2020-09-20 05:01:06 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-09-20 11:50:05 +0200 |
commit | e9a06bb9a2802a5ae6011fcd96cf54e1cfc7d311 (patch) | |
tree | bac0eab277ac64d6960dd433b7603393bbab2561 | |
parent | 483ec7256d6c4d01ba6c41513fdf8bbd7df6b4b3 (diff) | |
download | nitrokey-sys-rs-e9a06bb9a2802a5ae6011fcd96cf54e1cfc7d311.tar.gz nitrokey-sys-rs-e9a06bb9a2802a5ae6011fcd96cf54e1cfc7d311.tar.bz2 |
Derive Default for libnitrokey structs
This patch adds the --with-derive-default option to the bindgen
invocation so that it derives Default implementations for all
libnitrokey structs. This allows us to simplify code in nitrokey-rs,
for example the initialization of structs that are used in nitrokey-sys
functions with output parameters.
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | patches/deprecated.diff | 4 | ||||
-rw-r--r-- | src/ffi.rs | 15 |
4 files changed, 16 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a440ca1..a7af9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- Derive `Debug` for all structs generated by `bindgen`. + # v3.5.0 (2019-07-04) - Mark deprecated functions using the `deprecated` attribute. - Update to libnitrokey 3.5, causing all following changes. @@ -7,6 +7,7 @@ src/ffi.rs: ${LIBNITROKEY}/NK_C_API.h --whitelist-function "NK_.*" \ --whitelist-var "NK_.*" \ --whitelist-var "MAXIMUM_STR_REPLY_LENGTH" \ + --with-derive-default \ --output "$@" \ "$<" \ -- "-I${LIBNITROKEY}/libnitrokey" diff --git a/patches/deprecated.diff b/patches/deprecated.diff index a7d2359..c814812 100644 --- a/patches/deprecated.diff +++ b/patches/deprecated.diff @@ -6,7 +6,7 @@ Index: nitrokey-sys-rs/src/ffi.rs =================================================================== --- nitrokey-sys-rs.orig/src/ffi.rs +++ nitrokey-sys-rs/src/ffi.rs -@@ -762,6 +762,7 @@ extern "C" { +@@ -767,6 +767,7 @@ extern "C" { #[doc = " deprecated in favor of NK_get_status_as_string."] #[doc = " @return string representation of the status or an empty string"] #[doc = " if the command failed"] @@ -14,7 +14,7 @@ Index: nitrokey-sys-rs/src/ffi.rs pub fn NK_status() -> *mut ::std::os::raw::c_char; } extern "C" { -@@ -1017,6 +1018,7 @@ extern "C" { +@@ -1022,6 +1023,7 @@ extern "C" { pub fn NK_totp_set_time_soft(time: u64) -> ::std::os::raw::c_int; } extern "C" { @@ -79,9 +79,14 @@ fn bindgen_test_layout_NK_device_info() { ) ); } +impl Default for NK_device_info { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} #[doc = " Stores the common device status for all Nitrokey devices."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NK_status { #[doc = " The major firmware version, e. g. 0 in v0.40."] pub firmware_version_major: u8, @@ -196,7 +201,7 @@ fn bindgen_test_layout_NK_status() { } #[doc = " Stores the status of a Storage device."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NK_storage_status { #[doc = " Indicates whether the unencrypted volume is read-only."] pub unencrypted_volume_read_only: bool, @@ -447,7 +452,7 @@ fn bindgen_test_layout_NK_storage_status() { } #[doc = " Data about the usage of the SD card."] #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NK_SD_usage_data { #[doc = " The minimum write level, as a percentage of the total card"] #[doc = " size."] @@ -494,7 +499,7 @@ fn bindgen_test_layout_NK_SD_usage_data() { ); } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct NK_storage_ProductionTest { pub FirmwareVersion_au8: [u8; 2usize], pub FirmwareVersionInternal_u8: u8, @@ -1416,7 +1421,7 @@ extern "C" { ) -> ::std::os::raw::c_int; } #[repr(C)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone)] pub struct ReadSlot_t { pub slot_name: [u8; 15usize], pub _slot_config: u8, |