I'm trying to use neon
to produce bindings to a rust library. I am using serde
to handle the data, but it only has a macro for arrays defined up to length 32.
That macro code is:
macro_rules! array_impls {
($($len:tt)+) => {
$(
impl<T> Serialize for [T; $len]
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = try!(serializer.serialize_tuple($len));
for e in self {
try!(seq.serialize_element(e));
}
seq.end()
}
}
)+
}
}
array_impls! {
01 02 03 04 05 06 07 08 09 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32
}
I tried at first to paste the macro in and call array_impls! { 1024 }
, but rust won't allow modification of types from outside this crate, which the generic in the macro would potentially do.
My best guess as to a implementation is:
impl Serialize for [PolyCoeff; N] {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = serializer.serialize_tuple(N)?;
for e in self.iter_mut().enumerate() {
seq.serialize_element(e)?;
}
seq.end()
}
}
There are a couple of different errors. The main one is "this is not defined in the current crate because arrays are always foreign
".
I found a github issue for the array size limit. They suggested the following as a workaround:
struct S {
#[serde(serialize_with = "<[_]>::serialize")]
arr: [u8; 256],
}
I haven't been able to get it to compile yet.