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

Adding schnorrsig::KeyPair::from_secret_key convenience function #294

Merged
merged 1 commit into from
Jun 8, 2021

Conversation

dr-orlovsky
Copy link
Contributor

No description provided.

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.

ack bf9a276

@apoelstra apoelstra merged commit a5dfd09 into rust-bitcoin:master Jun 8, 2021
@Tibo-lg
Copy link
Contributor

Tibo-lg commented Jul 15, 2021

@dr-orlovsky is there a reason why the function doesn't borrow the secret key instead of taking ownership of it?

(also post merge nit, the ::key:: prefix seems unnecessary)

@dr-orlovsky
Copy link
Contributor Author

SecretKey's are copyable objects and impls for copyable objects should take self ownership, not reference, according to the Rust API guidelines

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Aug 2, 2021

@dr-orlovsky Thanks for answering. Do you have a reference to that guideline? I looked up a bit but the best I found is this clippy rule which doesn't indicate anything for from https://rust-lang.github.io/rust-clippy/master/#wrong_self_convention

The reason I find it a bit confusing personally is because the from_secret_key for PublicKey takes it as a reference so it feels a bit inconsistent.

@elichai
Copy link
Member

elichai commented Aug 2, 2021

IMHO @dr-orlovsky is generally right that Copy types should be passed by value, because that allows the compiler to make better optimizations usually (unless it's a non-inlinable function and the Copy type is bigger than say ~64 bytes).

But here because the C function cares just about a pointer to the type and the rest of the functions already pass by reference I think it would've been better to be a reference

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.

4 participants