From f1351e7e41e20e8cfe26e899caa6f7f209768747 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 23 Aug 2019 11:26:57 +0200 Subject: [PATCH] tools: add a static size assertion Signed-off-by: Wolfgang Bumiller --- proxmox-tools/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/proxmox-tools/src/lib.rs b/proxmox-tools/src/lib.rs index ee210fd7..02fcd158 100644 --- a/proxmox-tools/src/lib.rs +++ b/proxmox-tools/src/lib.rs @@ -19,6 +19,16 @@ macro_rules! offsetof { }; } +/// Static assertions +#[macro_export] +macro_rules! static_assert_size { + ($ty:ty, $size:expr) => { + const _: fn() -> () = || { + let _ = ::std::mem::transmute::<[u8; $size], $ty>; + }; + }; +} + /// Macro to write error-handling blocks (like perl eval {}) /// /// #### Example: