8000 Simplifying macros by elichai · Pull Request #356 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplifying macros #356

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

Merged
merged 1 commit into from
Oct 8, 2020
Merged

Conversation

elichai
Copy link
Member
@elichai elichai commented Dec 2, 2019

This is the first step in an attempt to simplify the macros we use in this crate.
I tried removing anything that can be derived. and removing the general functions implementation that might made sense on crates like rust-secp256k1 for ffi reasons but less so here.

cc #352
I'm trying to "Modernize" some of the great code @apoelstra wrote way before any of us ever heard of rust :)
The next stage is when these are simple enough I can write a custom derive crate for the rest of the things.

Sadly a thing that can greatly simplify the Index operations was is only stable from 1.28 rust-lang/rust#35729

The breaking changes are:

  1. removing a bunch of as_pt etc. implementations from ChainCode and Fingerprint (as I said before I don't think they make any sense here).
  2. removing a #[repr(C)] from the Uints.

anything else here shouldn't be considered a breaking change (exact implementations of traits like Hash etc aren't supposed to be stable anyway)

@codecov-io
Copy link
codecov-io commented Dec 2, 2019

Codecov Report

Merging #356 into master will decrease coverage by 0.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
- Coverage   85.74%   85.62%   -0.12%     
==========================================
  Files          40       40              
  Lines        7483     7597     +114     
==========================================
+ Hits         6416     6505      +89     
- Misses       1067     1092      +25     
Impacted Files Coverage Δ
src/internal_macros.rs 63.85% <100.00%> (+4.38%) ⬆️
src/network/constants.rs 85.27% <100.00%> (ø)
src/util/bip32.rs 87.24% <100.00%> (+0.10%) ⬆️
src/util/uint.rs 84.85% <100.00%> (+1.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a148e06...77589d2. Read the comment docs.

@elichai elichai changed the title Simplying macros Simplifying macros Dec 2, 2019
@stevenroose
Copy link
Collaborator

Ok so sometimes converting into and from the inner object is useful. F.e. when interfacing with code that doesn't know any bitcoin conventions. I also did it before with FFI's. Apart from that, I'd ACK.

Aaand it would be good to have in 0.22 perhaps since it's quite a big breaking change. But not a big deal if it's lateron.

@dr-orlovsky
Copy link
Collaborator

Would really love to see it merged. Can I help with adding the discussed changes to the PR?

@elichai
Copy link
Member Author
elichai commented Jan 11, 2020

I kinda left it for a while to get feedback on if people even want that (especially because of the complications in the follow up PR with the derive macros)

@dr-orlovsky
Copy link
Collaborator

I think that the level of current macro abuse in rust-bitcoin is too high and any more idiomatic code should be welcomed

@stevenroose
Copy link
Collaborator

I feel a bit double with all this. I think it'd be good to have 2 PRs: one that simply removes all impls that can be derived. Because that PR is a no-brainer.

But removing methods and replacing them with Rust traits is more tricky. I remember as a new user that I often lacked "simple" or "basic" methods. And using traits, while nifty and cool, is less intuitive. A Fingerprint might be nothing more than 4 bytes, it's still a Fingerprint (instance) in Rust. It's not trivial/intuitive for users that you can just use all the byte traits on it. I think the overhead of providing basic methods like as_bytes(&self) -> &[u8], to_bytes(&self) -> Vec<u8> and into_inner(&self) -> [u8; N] might be worth it. I also think it makes code more readable. fp.as_bytes() vs &fp[..] f.e.

@elichai
Copy link
Member Author
elichai commented Jan 23, 2020

I feel a bit double with all this. I think it'd be good to have 2 PRs: one that simply removes all impls that can be derived. Because that PR is a no-brainer.

You're right. I removed all controversial parts and left the impl ones.
If people prefer I can even squash these to 1 commit now

@elichai
Copy link
Member Author
elichai commented Jan 23, 2020

FYI CI failures are because of #398

stevenroose
stevenroose previously approved these changes Jan 23, 2020
@stevenroose
Copy link
Collaborator

Needs rebase.

apoelstra
apoelstra previously approved these changes Apr 5, 2020
Copy link
Member
@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ut / concept ACK

@elichai
Copy link
Member Author
elichai commented Apr 5, 2020

I honestly don't know how, but somehow the changes I reverted before(#356 (comment)) came back after the last rebase, I might've had an old version locally, although I'm not quite sure how.

Anyhow I modified it to look back as the original, and you can check yourself, the hash after the first rebase is: c9be13b0935fa3f4b2f570119000b77015dafaa3 and the current hash is: 77589d2e122f63768fe7fde880078e439875842d so:
git diff c9be13b0935fa3f4b2f570119000b77015dafaa3 77589d2e122f63768fe7fde880078e439875842d and look at the relevant files

@apoelstra
Copy link
Member

I think I'm looking at the latest code and there are still missing Hash derives for the bip32 types.

@elichai 8000
Copy link
Member Author
elichai commented Apr 20, 2020

Added the missing impls.

stevenroose
stevenroose previously approved these changes Apr 20, 2020
Copy link
Collaborator
@stevenroose stevenroose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK ef5e244

@elichai
Copy link
Member Author
elichai commented Sep 14, 2020

rebased

dr-orlovsky
dr-orlovsky previously approved these changes Sep 14, 2020
@dr-orlovsky
Copy link
Collaborator

utACK 02ddb27

@apoelstra
Copy link
Member
git rebase -x 'cargo test && cargo test --features "use-serde rand" && cargo +1.29.0 test' master

fails (first commit does not compile)

@apoelstra apoelstra merged commit 7c47c9a into rust-bitcoin:master Oct 8, 2020
@elichai elichai deleted the 2019-12-macros branch October 8, 2020 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0