Skip to content

Commit

Permalink
Add AsBytes implementation for fixed-length arrays
Browse files Browse the repository at this point in the history
It is now possible to do `tag!([42u8, 42u8])`

Fix #54
  • Loading branch information
Geal committed Jun 24, 2015
1 parent b8de871 commit 8bce0ec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,34 @@ impl AsBytes for [u8] {
}
}

macro_rules! array_impls {
($($N:expr)+) => {
$(
impl<'a> AsBytes for &'a [u8; $N] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
*self
}
}

impl AsBytes for [u8; $N] {
#[inline(always)]
fn as_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
}

pub enum ErrorCode {
Tag,
MapRes,
Expand Down

0 comments on commit 8bce0ec

Please sign in to comment.