aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-20 11:40:09 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-02-20 12:50:25 +0100
commit0d162c3d9e6a220fe30768bedcb129bf04a2cc7b (patch)
tree926faf97c7ba1233289290a936db8d7b7c0a8384
parent990063fb3ecfc6baeb51e4f57b3f75ee16bac56e (diff)
downloadntw-0d162c3d9e6a220fe30768bedcb129bf04a2cc7b.tar.gz
ntw-0d162c3d9e6a220fe30768bedcb129bf04a2cc7b.tar.bz2
Use arrays instead of slices where possible
To increase type safety, we use references to (sized) arrays instead of slices where possible.
-rw-r--r--src/commands.rs4
-rw-r--r--src/util.rs6
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<C: Command>(data: &[u8], buf: &mut [u8]) -> CommandStatus {
+fn execute<C: Command>(data: &RequestData, buf: &mut ResponseData) -> CommandStatus {
// TODO: better error if (de-)serialization fails
if let Ok((request, _)) = ssmarshal::deserialize::<C::Request>(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),