aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-20 12:31:45 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-02-20 14:09:40 +0100
commit4b436755d5895cb7113bee135d451cdeb2cf465a (patch)
treee198bfeebefd1e8e1252bd05b049d8c3ec13b5f2 /src/util.rs
parente0d33dae2f2ab70b936467590284030d759f9db7 (diff)
downloadntw-4b436755d5895cb7113bee135d451cdeb2cf465a.tar.gz
ntw-4b436755d5895cb7113bee135d451cdeb2cf465a.tar.bz2
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.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs9
1 files changed, 9 insertions, 0 deletions
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<T>: Sized {
fn try_from(val: T) -> Result<Self, ()>;
}