From ebaa6210a40a0220f332ea6f88b501323afb2690 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Mar 2024 17:51:16 +0100 Subject: [PATCH 1/3] add from impls --- src/ecss/mod.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ecss/mod.rs b/src/ecss/mod.rs index 03c7a31..d7541db 100644 --- a/src/ecss/mod.rs +++ b/src/ecss/mod.rs @@ -360,10 +360,28 @@ impl> EcssEn { } -pub type EcssEnumU8 = GenericEcssEnumWrapper; -pub type EcssEnumU16 = GenericEcssEnumWrapper; -pub type EcssEnumU32 = GenericEcssEnumWrapper; -pub type EcssEnumU64 = GenericEcssEnumWrapper; +macro_rules! impl_from_for_generic_ecss_enum_wrapper { + ($($ty:ty => $Enum:ident),*) => { + $( + pub type $Enum = GenericEcssEnumWrapper<$ty>; + + impl From<$ty> for $Enum { + fn from(value: $ty) -> Self { + Self::new(value) + } + } + )* + }; +} + +// Generates EcssEnum<$TY> type definitions as well as a From<$TY> for EcssEnum<$TY> +// implementation. +impl_from_for_generic_ecss_enum_wrapper! { + u8 => EcssEnumU8, + u16 => EcssEnumU16, + u32 => EcssEnumU32, + u64 => EcssEnumU64 +} /// Generic trait for PUS packet abstractions which can written to a raw slice as their raw /// byte representation. This is especially useful for generic abstractions which depend only From 64ea7e609db7728e7abd5a0759ce65f61391581f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Mar 2024 17:52:51 +0100 Subject: [PATCH 2/3] better naming --- src/ecss/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ecss/mod.rs b/src/ecss/mod.rs index d7541db..dd2351c 100644 --- a/src/ecss/mod.rs +++ b/src/ecss/mod.rs @@ -360,7 +360,7 @@ impl> EcssEn { } -macro_rules! impl_from_for_generic_ecss_enum_wrapper { +macro_rules! generic_ecss_enum_typedefs_and_from_impls { ($($ty:ty => $Enum:ident),*) => { $( pub type $Enum = GenericEcssEnumWrapper<$ty>; @@ -376,7 +376,7 @@ macro_rules! impl_from_for_generic_ecss_enum_wrapper { // Generates EcssEnum<$TY> type definitions as well as a From<$TY> for EcssEnum<$TY> // implementation. -impl_from_for_generic_ecss_enum_wrapper! { +generic_ecss_enum_typedefs_and_from_impls! { u8 => EcssEnumU8, u16 => EcssEnumU16, u32 => EcssEnumU32, From e4730d4b8f0bea4dc78975cb76b722d378d46f5c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Mar 2024 17:54:02 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbfa298..7bd20fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # [unreleased] +## Added + +- Added `From<$TY>` for the `EcssEnum$TY` ECSS enum type definitions. + # [v0.10.0] 2024-02-17 ## Added