Merge pull request #548 from apoelstra/2021-01--more-encodable
encode: add some more generic impls (more tuples, references)
This commit is contained in:
commit
fd41157746
|
@ -66,6 +66,11 @@ cargo update --package "serde" --precise "1.0.98"
|
||||||
cargo update --package "serde_derive" --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
|
## Installing Rust
|
||||||
Rust can be installed using your package manager of choice or
|
Rust can be installed using your package manager of choice or
|
||||||
[rustup.rs](https://rustup.rs). The former way is considered more secure since
|
[rustup.rs](https://rustup.rs). The former way is considered more secure since
|
||||||
|
|
|
@ -2,12 +2,17 @@
|
||||||
|
|
||||||
FEATURES="base64 bitcoinconsensus use-serde rand"
|
FEATURES="base64 bitcoinconsensus use-serde rand"
|
||||||
|
|
||||||
# Pin `cc` for Rust 1.29
|
pin_common_verions() {
|
||||||
if [ -n "$PIN_VERSIONS" ]; then
|
|
||||||
cargo generate-lockfile --verbose
|
cargo generate-lockfile --verbose
|
||||||
cargo update -p cc --precise "1.0.41" --verbose
|
cargo update -p cc --precise "1.0.41" --verbose
|
||||||
cargo update -p serde --precise "1.0.98" --verbose
|
cargo update -p serde --precise "1.0.98" --verbose
|
||||||
cargo update -p serde_derive --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
|
fi
|
||||||
|
|
||||||
if [ "$DO_COV" = true ]
|
if [ "$DO_COV" = true ]
|
||||||
|
@ -58,10 +63,7 @@ then
|
||||||
|
|
||||||
# Pin `cc` for Rust 1.29
|
# Pin `cc` for Rust 1.29
|
||||||
if [ -n "$PIN_VERSIONS" ]; then
|
if [ -n "$PIN_VERSIONS" ]; then
|
||||||
cargo generate-lockfile --verbose
|
pin_common_verions
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cargo test --verbose
|
cargo test --verbose
|
||||||
|
|
|
@ -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
|
// Tuples
|
||||||
macro_rules! tuple_encode {
|
macro_rules! tuple_encode {
|
||||||
($($x:ident),*) => (
|
($($x:ident),*) => (
|
||||||
|
@ -707,8 +732,11 @@ macro_rules! tuple_encode {
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple_encode!(T0, T1);
|
tuple_encode!(T0, T1);
|
||||||
|
tuple_encode!(T0, T1, T2);
|
||||||
tuple_encode!(T0, T1, T2, T3);
|
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);
|
||||||
|
tuple_encode!(T0, T1, T2, T3, T4, T5, T6);
|
||||||
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
|
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
|
||||||
|
|
||||||
impl Encodable for sha256d::Hash {
|
impl Encodable for sha256d::Hash {
|
||||||
|
|
Loading…
Reference in New Issue