aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-20 11:47:25 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-02-20 12:50:32 +0100
commite0d33dae2f2ab70b936467590284030d759f9db7 (patch)
tree640189baa73af6d736b871b2bc4052f31086646a /src
parent0d162c3d9e6a220fe30768bedcb129bf04a2cc7b (diff)
downloadntw-e0d33dae2f2ab70b936467590284030d759f9db7.tar.gz
ntw-e0d33dae2f2ab70b936467590284030d759f9db7.tar.bz2
Add static assertions for Request and Response size
The Request and Response types have to have a size of 64 bytes. Previously, we only verified this property by visual inspection. Accidental changes to the size could lead to runtime errors. This patch adds static assertions using the static_assertions crate to enforce this property at compile time.
Diffstat (limited to 'src')
-rw-r--r--src/device.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/device.rs b/src/device.rs
index b25cfb7..8f6f6ef 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -3,6 +3,7 @@
use serde::{Deserialize, Serialize};
use serde_big_array::big_array;
+use static_assertions::assert_eq_size;
use usb_device::bus::{UsbBus, UsbBusAllocator};
use usb_device::device::{UsbDevice, UsbDeviceBuilder, UsbVidPid};
@@ -65,6 +66,8 @@ struct Request {
pub crc: u32,
}
+assert_eq_size!(request; [u8; REPORT_LEN], Request);
+
#[derive(Serialize)]
struct Response {
pub device_status: DeviceStatus,
@@ -76,6 +79,8 @@ struct Response {
pub crc: u32,
}
+assert_eq_size!(response; [u8; REPORT_LEN], Response);
+
impl Response {
fn new(device_status: DeviceStatus, command_id: u8, last_crc: u32) -> Response {
Response {