diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-02-19 12:55:45 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-19 14:54:07 +0100 |
commit | ffb3d8f11b232e811bebfe0c9b450a8a95a7b12b (patch) | |
tree | c0a9093c785a853a96fd0549078bce1cafe8ee3d /src | |
parent | dbcbc8472543d5c5b24bf6ce281637a9a8a70098 (diff) | |
download | ntw-ffb3d8f11b232e811bebfe0c9b450a8a95a7b12b.tar.gz ntw-ffb3d8f11b232e811bebfe0c9b450a8a95a7b12b.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.rs | 6 |
1 files changed, 6 insertions, 0 deletions
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<S: ::serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { + serializer.serialize_u8((*self).into()) + } + } + impl From<$name> for u8 { fn from(val: $name) -> u8 { val as u8 |