Skip to content

Big integers (Uint*) from byte slice array with from_be_bytes#436

Merged
apoelstra merged 2 commits intorust-bitcoin:masterfrom
BP-WG:feat-u256u8
Sep 9, 2020
Merged

Big integers (Uint*) from byte slice array with from_be_bytes#436
apoelstra merged 2 commits intorust-bitcoin:masterfrom
BP-WG:feat-u256u8

Conversation

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

No description provided.

@elichai
Copy link
Copy Markdown
Member

elichai commented Jun 21, 2020

Could you please implement this without heap allocations?
also, you can add a slice_to_u64_be here and use that:

define_slice_to_be!(slice_to_u32_be, u32);

Copy link
Copy Markdown
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.

Hmm, it reads correctly, but I'd be happier with a unit test.

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

also, you can add a slice_to_u64_be here and use that:

@elichai I did, but it fails to compile since this function is not being used from anywhere (i.e. triggers dead_code error):

error: function is never used: `slice_to_u64_be`
  --> src/util/endian.rs:4:9
   |
4  |         pub fn $name(slice: &[u8]) -> $type {
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
55 | define_slice_to_be!(slice_to_u64_be, u64);
   | ------------------------------------------ in this macro invocation
   |
note: the lint level is defined here
  --> src/lib.rs:43:9
   |
43 | #![deny(dead_code)]
   |         ^^^^^^^^^
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

@elichai
Copy link
Copy Markdown
Member

elichai commented Jul 21, 2020

I meant that you'll use that instead of: u64::from_be_bytes(...) (for MSRV reasons)

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

Oh yes, true

@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

done

stevenroose
stevenroose previously approved these changes Aug 9, 2020
@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

Now, with #435 merged, it will be nice to merge this one as well before the next version release

Copy link
Copy Markdown
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

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

Looks good. I think it could be more readable/idiomatic if it used iterators.

Co-authored-by: Sebastian <geisler.sebastian@googlemail.com>
@dr-orlovsky
Copy link
Copy Markdown
Collaborator Author

dr-orlovsky commented Sep 3, 2020

Btw, trying to understand how util::endianis different from https://github.com/rust-bitcoin/bitcoin_hashes/blob/master/src/util.rs#L149-L210 and why not to move there all these functions (old and new ones)? It looks like just a copy-past from bitcoin_hashes::util

Updt: created an issue for that #467 This can be fixed independently from this PR

Copy link
Copy Markdown
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.

utACK

@apoelstra apoelstra merged commit c8633b5 into rust-bitcoin:master Sep 9, 2020
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.

6 participants