Skip to content

Commit 1d1ad54

Browse files
committed
Merge pull request SSheldon#10 madsmtm/const-generics
Implement `Encode` for arrays using const generics
2 parents ce6a1ef + 9f9f5f2 commit 1d1ad54

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

objc_encode/src/encode.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,10 @@ 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-
};
66+
unsafe impl<T: Encode, const LENGTH: usize> Encode for [T; LENGTH] {
67+
const ENCODING: Encoding<'static> = Encoding::Array(LENGTH as u32, &<T as Encode>::ENCODING);
7568
}
7669

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-
8270
// External crates cannot implement Encode for pointers or [`Option`], but
8371
// they *can* implement it for references. See
8472
// [rust-lang/rust#25126](https://github.com/rust-lang/rust/issues/25126)

0 commit comments

Comments
 (0)