Impl encodable/decodable for the array newtypes
This commit is contained in:
parent
17daebf15d
commit
71312b032a
|
@ -89,6 +89,35 @@ macro_rules! impl_array_newtype(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: ::serialize::Decoder<E>, E> ::serialize::Decodable<D, E> for $thing {
|
||||||
|
fn decode(d: &mut D) -> ::std::prelude::Result<$thing, E> {
|
||||||
|
use serialize::Decodable;
|
||||||
|
|
||||||
|
::assert_type_is_copy::<$ty>();
|
||||||
|
|
||||||
|
d.read_seq(|d, len| {
|
||||||
|
if len != $len {
|
||||||
|
Err(d.error("Invalid length"))
|
||||||
|
} else {
|
||||||
|
unsafe {
|
||||||
|
use std::mem;
|
||||||
|
let mut ret: [$ty, ..$len] = mem::uninitialized();
|
||||||
|
for i in range(0, len) {
|
||||||
|
ret[i] = try!(d.read_seq_elt(i, |d| Decodable::decode(d)));
|
||||||
|
}
|
||||||
|
Ok($thing(ret))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<E: ::serialize::Encoder<S>, S> ::serialize::Encodable<E, S> for $thing {
|
||||||
|
fn encode(&self, e: &mut E) -> ::std::prelude::Result<(), S> {
|
||||||
|
self.as_slice().encode(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ pub mod constants;
|
||||||
pub mod ffi;
|
pub mod ffi;
|
||||||
pub mod key;
|
pub mod key;
|
||||||
|
|
||||||
|
/// I dunno where else to put this..
|
||||||
|
fn assert_type_is_copy<T: Copy>() { }
|
||||||
|
|
||||||
/// A tag used for recovering the public key from a compact signature
|
/// A tag used for recovering the public key from a compact signature
|
||||||
pub struct RecoveryId(i32);
|
pub struct RecoveryId(i32);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue