From e9a06bb9a2802a5ae6011fcd96cf54e1cfc7d311 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 20 Sep 2020 05:01:06 +0200 Subject: 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. --- src/ffi.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ffi.rs b/src/ffi.rs index 810660f..f81982e 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -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, -- cgit v1.2.1