Merge pull request #548 from apoelstra/2021-01--more-encodable

encode: add some more generic impls (more tuples, references)
This commit is contained in:
Andrew Poelstra 2021-01-09 23:55:26 +00:00 committed by GitHub
commit fd41157746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 6 deletions

View File

@ -66,6 +66,11 @@ cargo update --package "serde" --precise "1.0.98"
cargo update --package "serde_derive" --precise "1.0.98"
```
For the feature `base64` to work with 1.29.0 we also need to pin `byteorder`:
```
cargo update -p byteorder --precise "1.3.4"
```
## Installing Rust
Rust can be installed using your package manager of choice or
[rustup.rs](https://rustup.rs). The former way is considered more secure since

View File

@ -2,12 +2,17 @@
FEATURES="base64 bitcoinconsensus use-serde rand"
# Pin `cc` for Rust 1.29
if [ -n "$PIN_VERSIONS" ]; then
pin_common_verions() {
cargo generate-lockfile --verbose
cargo update -p cc --precise "1.0.41" --verbose
cargo update -p serde --precise "1.0.98" --verbose
cargo update -p serde_derive --precise "1.0.98" --verbose
}
# Pin `cc` for Rust 1.29
if [ -n "$PIN_VERSIONS" ]; then
pin_common_verions
cargo update -p byteorder --precise "1.3.4"
fi
if [ "$DO_COV" = true ]
@ -58,10 +63,7 @@ then
# Pin `cc` for Rust 1.29
if [ -n "$PIN_VERSIONS" ]; then
cargo generate-lockfile --verbose
cargo update -p cc --precise "1.0.41" --verbose
cargo update -p serde --precise "1.0.98" --verbose
cargo update -p serde_derive --precise "1.0.98" --verbose
pin_common_verions
fi
cargo test --verbose

View File

@ -679,6 +679,31 @@ impl Decodable for CheckedData {
}
}
// References
impl<'a, T: Encodable> Encodable for &'a T {
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, Error> {
(&**self).consensus_encode(s)
}
}
impl<'a, T: Encodable> Encodable for &'a mut T {
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, Error> {
(&**self).consensus_encode(s)
}
}
impl<T: Encodable> Encodable for ::std::rc::Rc<T> {
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, Error> {
(&**self).consensus_encode(s)
}
}
impl<T: Encodable> Encodable for ::std::sync::Arc<T> {
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, Error> {
(&**self).consensus_encode(s)
}
}
// Tuples
macro_rules! tuple_encode {
($($x:ident),*) => (
@ -707,8 +732,11 @@ macro_rules! tuple_encode {
}
tuple_encode!(T0, T1);
tuple_encode!(T0, T1, T2);
tuple_encode!(T0, T1, T2, T3);
tuple_encode!(T0, T1, T2, T3, T4);
tuple_encode!(T0, T1, T2, T3, T4, T5);
tuple_encode!(T0, T1, T2, T3, T4, T5, T6);
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
impl Encodable for sha256d::Hash {