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

Add u5 type and traits #17

Merged
merged 5 commits into from
May 2, 2018
Merged

Add u5 type and traits #17

merged 5 commits into from
May 2, 2018

Conversation

sgeisler
Copy link
Contributor

@sgeisler sgeisler commented Apr 6, 2018

Fixes #16. I'm not really sure if the API is as good as it could be. I will have a look at rust-bech32-bitcoin and prepare a PR to fix any emerging incompatibilities. Maybe this will show me some rough edges which I can improve.

@sgeisler sgeisler self-assigned this Apr 6, 2018
src/lib.rs Outdated
@@ -50,41 +50,140 @@ use std::{error, fmt};
use std::str::FromStr;
use std::fmt::{Display, Formatter};

#[cfg(feature = "try_from")]
Copy link
Member

Choose a reason for hiding this comment

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

What is the compatibility of try_from? Other changes were made to this library to push compatibility back to 1.14.

Copy link
Contributor Author

@sgeisler sgeisler Apr 6, 2018

Choose a reason for hiding this comment

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

AFAIK it's new in 1.25, that's why I put it behind a feature gate. You can use it if your rustc version is new enough, but you can ignore it otherwise. Unfortunately I couldn't find a way to express "only activate if rustc version >= 1.25.0", so the user has to activate it manually. But this reminds me of a TODO: run the stable test with the feature activated and add a test for TryFrom.

EDIT: My reasoning behind this is: with the next debian release a new rustc version will be included. If new traits are already implemented it becomes much easier to upgrade the API: just deprecate and at some point remove the old methods.

Copy link
Contributor Author

@sgeisler sgeisler Apr 15, 2018

Choose a reason for hiding this comment

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

Although some stabilization PR for TryFrom was merged recently it seems not to work on 1.25. I will remove the feature.

src/lib.rs Outdated
/// Integer in the range `0..32`
#[derive(PartialEq, Debug, Copy, Clone, Default)]
#[allow(non_camel_case_types)]
#[repr(C)]
Copy link
Contributor Author

@sgeisler sgeisler Apr 6, 2018

Choose a reason for hiding this comment

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

remove repr(C), was used to do tests with std::mem::transmute

@clarkmoody
Copy link
Member

You've got a few TODOs still in the code. Were you doing to address those before moving forward with this?

@sgeisler
Copy link
Contributor Author

I will defineatly address them, that's why I marked the PR as WIP. But right now I'm using the API with bech32-bitcoin and lightning-invoice to find rough edges. I already found some and will fix them next.

@sgeisler sgeisler changed the title WIP: Add u5 type and traits Add u5 type and traits Apr 15, 2018
@sgeisler
Copy link
Contributor Author

Imo the PR is ready for review now. I have two naming decisions that I'm not completely sure about:

  • FromBech32 vs. TryFromBech32
  • Bech32::new_check_data for the constructor that accepts arbitrary u8 data vectors, but may return Err(Error::InvalidData).

@apoelstra
Copy link
Member

Can you squash down the TODO fixes? Note that you can selectively squash with git rebase -i.

@sgeisler
Copy link
Contributor Author

I could squash all of the commits if you wanted, but IMO a merge will hide the commits behind one and everyone interested can still look at this PR.

@apoelstra
Copy link
Member

It's very hard to review changes where commits introduce things that other commits remove.

@sgeisler
Copy link
Contributor Author

With some squashing and rebasing I cut the commit count down to four. I hope this is a better starting point for a review.

@clarkmoody
Copy link
Member

I will try to review soon.

Copy link
Member

@clarkmoody clarkmoody left a comment

Choose a reason for hiding this comment

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

It will be nice to have the guarantees of bounded values for the u5 data type when doing Bech32 stuff.

Thanks!

@clarkmoody
Copy link
Member

@apoelstra Any comments before we merge?

@sgeisler
Copy link
Contributor Author

sgeisler commented Apr 30, 2018

I just saw that I didn't increase the version yet. I guess it would be 0.4.0? EDIT: and I need to sync the README with the examples from the docs.

* set version to 0.4.0
* use examples from rustdoc in README
@clarkmoody
Copy link
Member

👍 I was thinking about that earlier. Thanks

@clarkmoody clarkmoody merged commit 09b90a9 into rust-bitcoin:master May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define u5 type to distinguish between 5bit and 8bit slices
3 participants