Skip to content

Commit 70c6d1a

Browse files
committed
impl Encode for [N; T], where 1 <= N <= 32, T: Encode
1 parent aa345a8 commit 70c6d1a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/encode.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ unsafe impl Encode for *const c_void {
6363
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
6464
}
6565

66+
// TODO: Replace this with a const generics implementation when they stabilise (#44580)
67+
macro_rules! slice_encode_impl {
68+
($($n:literal),* $(,)?) => {
69+
$(
70+
unsafe impl<T: Encode> Encode for [T; $n] {
71+
const ENCODING: Encoding<'static> = Encoding::Array($n, &<T as Encode>::ENCODING);
72+
}
73+
)*
74+
};
75+
}
76+
77+
slice_encode_impl!(
78+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
79+
27, 28, 29, 30, 31, 32
80+
);
81+
6682
/*
6783
External crates cannot implement Encode for pointers or Optionals, but they
6884
*can* implement it for references. rust-lang/rust#25126

0 commit comments

Comments
 (0)