-
Notifications
You must be signed in to change notification settings - Fork 729
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
Allow easy concatenation of bip32 derivation paths #459
Allow easy concatenation of bip32 derivation paths #459
Conversation
6965a26
to
195fad1
Compare
|
src/util/bip32.rs
Outdated
@@ -326,6 +326,12 @@ impl DerivationPath { | |||
pub fn hardened_children(&self) -> DerivationPathIterator { | |||
DerivationPathIterator::start_from(&self, ChildNumber::Hardened{ index: 0 }) | |||
} | |||
|
|||
pub fn extend(&self, path: impl AsRef<[ChildNumber]>) -> DerivationPath { | |||
let mut path = self.clone(); |
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.
-
you override the
path
input variable here -
why does this create a new DerivationPath instead of extending the current? (I see that
child()
does the same) -
why is
impl AsRef<[ChildNumber]>
better than a simple&[ChildNumber]
?
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.
Number 3 makes this non-compiling for the current MSRV btw
Currently one has to convert the path into a Vec<ChildNumber>, extend it and finally convert it back again.
195fad1
to
202a946
Compare
Sorry, fixed.
|
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.
I think more idiomatic way of doing this may be
pub fn extend<T: IntoIterator<Item=ChildNumber>>(&self, path: T) -> DerivationPath {
self.into_iter(0).chain(path).collect()
}
This will require impl IntoIter for DerivationPath
, but this is trivial and will be useful anyway
Also, if you will choose that route, I propose to impl ExactSizeIterator for DerivationPath
as well
PS: the current travis failure seems related to #468 |
Could you give a concrete example of what it will allow that |
concept ACK. I'm a little ambivalent about using |
Also tested ACK |
Currently one has to convert the path into a
Vec<ChildNumber>
, extend it and finally convert it back again.