From 4b436755d5895cb7113bee135d451cdeb2cf465a Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 20 Feb 2019 12:31:45 +0000 Subject: Assert maximum size for command request and response structs The request and response structs for a command should not be bigger than the buffer they are read from or written to. Therefore we add assertions that enforce this property at compile time. --- src/util.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/util.rs') diff --git a/src/util.rs b/src/util.rs index c86d047..7b12afb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -77,6 +77,15 @@ macro_rules! enum_u8 { }; } +macro_rules! assert_maximum_size { + ($i:ident; $t:ident, $e: expr) => { + ::static_assertions::const_assert!( + $i; + ::core::mem::size_of::<$t>() <= $e + ); + } +} + pub trait TryFrom: Sized { fn try_from(val: T) -> Result; } -- cgit v1.2.1