Skip to content

Commit

Permalink
impl Encode for [N; T], where 1 <= N <= 32, T: Encode
Browse files Browse the repository at this point in the history
  • Loading branch information
burtonageo committed Oct 7, 2019
1 parent aa345a8 commit 70c6d1a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ unsafe impl Encode for *const c_void {
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
}

// TODO: Replace this with a const generics implementation when they stabilise (#44580)
macro_rules! slice_encode_impl {
($($n:literal),* $(,)?) => {
$(
unsafe impl<T: Encode> Encode for [T; $n] {
const ENCODING: Encoding<'static> = Encoding::Array($n, &<T as Encode>::ENCODING);
}
)*
};
}

slice_encode_impl!(
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,
27, 28, 29, 30, 31, 32
);

/*
External crates cannot implement Encode for pointers or Optionals, but they
*can* implement it for references. rust-lang/rust#25126
Expand Down

0 comments on commit 70c6d1a

Please sign in to comment.