Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode: add some more generic impls (more tuples, references) #548

Merged
merged 2 commits into from Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions contrib/test.sh
Expand Up @@ -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 ]
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/consensus/encode.rs
Expand Up @@ -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)
sgeisler marked this conversation as resolved.
Show resolved Hide resolved
}
}

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),*) => (
Expand Down Expand Up @@ -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 {
Expand Down