Skip to content

Commit

Permalink
Impl ToBytes for [u8; N] with generic const
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborg42 authored and fede1024 committed Aug 6, 2024
1 parent e7d863f commit 5f6a2c5
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,24 +822,12 @@ impl ToBytes for () {
}
}

// Implement to_bytes for arrays - https://github.com/rust-lang/rfcs/issues/1038
macro_rules! array_impls {
($($N:expr)+) => {
$(
impl ToBytes for [u8; $N] {
fn to_bytes(&self) -> &[u8] { self }
}
)+
impl<const N: usize> ToBytes for [u8; N] {
fn to_bytes(&self) -> &[u8] {
self
}
}

array_impls! {
0 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
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 5f6a2c5

Please sign in to comment.