`defmt::export::sealed`: Make trunacate-direction more clear
@@ -7,7 +7,7 @@ pub trait Truncate<U> {
}
macro_rules! impl_truncate {
- ($t:ty, $u:ty) => {
+ ($t:ty => $u:ty) => {
impl Truncate<$t> for $u {
fn truncate(self) -> $t {
self as $t
@@ -16,29 +16,24 @@ macro_rules! impl_truncate {
};
}
-impl_truncate!(u8, u8);
-impl_truncate!(u8, u16);
-impl_truncate!(u8, u32);
-impl_truncate!(u8, u64);
-impl_truncate!(u8, u128);
-
-// needed so we can call truncate() without having to check whether truncation is necessary first
-impl_truncate!(u16, u16);
-impl_truncate!(u16, u32);
-impl_truncate!(u16, u64);
-impl_truncate!(u16, u128);
-
-// needed so we can call truncate() without having to check whether truncation is necessary first
-impl_truncate!(u32, u32);
-impl_truncate!(u32, u64);
-impl_truncate!(u32, u128);
-
-// needed so we can call truncate() without having to check whether truncation is necessary first
-impl_truncate!(u64, u64);
-impl_truncate!(u64, u128);
-
-// needed so we can call truncate() without having to check whether truncation is necessary first
-impl_truncate!(u128, u128);
+// We implement Truncate<X> for X so that the macro can unconditionally use it,
+// even if no truncation is performed.
+
+impl_truncate!(u8 => u8);
+impl_truncate!(u8 => u16);
+impl_truncate!(u8 => u32);
+impl_truncate!(u8 => u64);
+impl_truncate!(u8 => u128);
+impl_truncate!(u16 => u16);
+impl_truncate!(u16 => u32);
+impl_truncate!(u16 => u64);
+impl_truncate!(u16 => u128);
+impl_truncate!(u32 => u32);
+impl_truncate!(u32 => u64);
+impl_truncate!(u32 => u128);
+impl_truncate!(u64 => u64);
+impl_truncate!(u64 => u128);
+impl_truncate!(u128 => u128);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct NoneError;
