-
Notifications
You must be signed in to change notification settings - Fork 150
Replace macros with traits; other cleanups #650
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ec0f44
add `blanket_traits` module to replace very noisy trait definitions
apoelstra 270e65d
Replace macros with blanket impls
apoelstra be41d8b
miniscript: add constants for 1 and 0
apoelstra f22dc3a
miniscript: use new TRUE/FALSE constants throughout the codebase
apoelstra 30d2d11
miniscript: factor out a couple parts of Terminal::from_tree
apoelstra bbafc39
expression: add parsing benchmark
apoelstra 164bde9
miniscript: add parsing benchmarks
apoelstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
//! Blanket Traits | ||
//! | ||
//! Because of this library's heavy use of generics, we often require complicated | ||
//! trait bounds (especially when it comes to [`FromStr`] and its | ||
//! associated error types). These blanket traits act as aliases, allowing easier | ||
//! descriptions of them. | ||
//! | ||
//! While these traits are not sealed, they have blanket-impls which prevent you | ||
//! from directly implementing them on your own types. The traits will be | ||
//! automatically implemented if you satisfy all the bounds. | ||
//! | ||
|
||
use core::fmt; | ||
use core::str::FromStr; | ||
|
||
use crate::MiniscriptKey; | ||
|
||
/// Blanket trait describing a key where all associated types implement `FromStr`, | ||
/// and all `FromStr` errors can be displayed. | ||
pub trait FromStrKey: | ||
MiniscriptKey< | ||
Sha256 = Self::_Sha256, | ||
Hash256 = Self::_Hash256, | ||
Ripemd160 = Self::_Ripemd160, | ||
Hash160 = Self::_Hash160, | ||
> + FromStr<Err = Self::_FromStrErr> | ||
{ | ||
/// Dummy type. Do not use. | ||
type _Sha256: FromStr<Err = Self::_Sha256FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Sha256FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Hash256: FromStr<Err = Self::_Hash256FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Hash256FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Ripemd160: FromStr<Err = Self::_Ripemd160FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Ripemd160FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _Hash160: FromStr<Err = Self::_Hash160FromStrErr>; | ||
/// Dummy type. Do not use. | ||
type _Hash160FromStrErr: fmt::Debug + fmt::Display; | ||
/// Dummy type. Do not use. | ||
type _FromStrErr: fmt::Debug + fmt::Display; | ||
} | ||
|
||
impl<T> FromStrKey for T | ||
where | ||
Self: MiniscriptKey + FromStr, | ||
<Self as MiniscriptKey>::Sha256: FromStr, | ||
Self::Hash256: FromStr, | ||
Self::Ripemd160: FromStr, | ||
Self::Hash160: FromStr, | ||
<Self as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<<Self as MiniscriptKey>::Sha256 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Hash256 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Ripemd160 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
<Self::Hash160 as FromStr>::Err: fmt::Debug + fmt::Display, | ||
{ | ||
type _Sha256 = <T as MiniscriptKey>::Sha256; | ||
type _Sha256FromStrErr = <<T as MiniscriptKey>::Sha256 as FromStr>::Err; | ||
type _Hash256 = <T as MiniscriptKey>::Hash256; | ||
type _Hash256FromStrErr = <<T as MiniscriptKey>::Hash256 as FromStr>::Err; | ||
type _Ripemd160 = <T as MiniscriptKey>::Ripemd160; | ||
type _Ripemd160FromStrErr = <<T as MiniscriptKey>::Ripemd160 as FromStr>::Err; | ||
type _Hash160 = <T as MiniscriptKey>::Hash160; | ||
type _Hash160FromStrErr = <<T as MiniscriptKey>::Hash160 as FromStr>::Err; | ||
type _FromStrErr = <T as FromStr>::Err; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I rekon we should import
FromStrKey
and use the more terse<Pk: FromStrKey>
since inline trait bounds are noisy enough as it is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Will do this as a followup (or you are welcome to).