From 0d162c3d9e6a220fe30768bedcb129bf04a2cc7b Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 20 Feb 2019 11:40:09 +0000 Subject: Use arrays instead of slices where possible To increase type safety, we use references to (sized) arrays instead of slices where possible. --- src/commands.rs | 4 ++-- src/util.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d05423e..99e049f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,7 +6,7 @@ use core::default::Default; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; -use crate::device::CommandStatus; +use crate::device::{CommandStatus, RequestData, ResponseData}; enum_cmd! { #[derive(Clone, Copy, Debug, PartialEq)] @@ -79,7 +79,7 @@ impl Command for ReadSlotNameCommand { } } -fn execute(data: &[u8], buf: &mut [u8]) -> CommandStatus { +fn execute(data: &RequestData, buf: &mut ResponseData) -> CommandStatus { // TODO: better error if (de-)serialization fails if let Ok((request, _)) = ssmarshal::deserialize::(data) { match C::execute(request) { diff --git a/src/util.rs b/src/util.rs index cbe7c0d..c86d047 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,7 +21,11 @@ macro_rules! enum_cmd { } impl $name { - pub fn execute(&self, data: &[u8], buf: &mut [u8]) -> CommandStatus { + pub fn execute( + &self, + data: &crate::device::RequestData, + buf: &mut crate::device::ResponseData, + ) -> CommandStatus { match *self { $( $name::$var => crate::commands::execute::<$cmd>(data, buf), -- cgit v1.2.1