From ffb3d8f11b232e811bebfe0c9b450a8a95a7b12b Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 19 Feb 2019 12:55:45 +0000 Subject: Implement serde::Serialize in enum_u8 By providing a custom Serialize implementation, we make sure that enum variants are not mapped to their index, but to their discriminant. This allows us to use serde when preparing the response packet. --- src/util.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util.rs b/src/util.rs index c83d3f3..cbe7c0d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -59,6 +59,12 @@ macro_rules! enum_u8 { } } + impl ::serde::Serialize for $name { + fn serialize(&self, serializer: S) -> Result { + serializer.serialize_u8((*self).into()) + } + } + impl From<$name> for u8 { fn from(val: $name) -> u8 { val as u8 -- cgit v1.2.1