Skip to content

Commit 3d935aa

Browse files
committed
Improve rustdocs on primary traits
The `MiniscriptKey` and `ToPublicKey` traits are more-or-less the first point of call for users of this library, lets clean them up.
1 parent a8a5698 commit 3d935aa

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/lib.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,16 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
162162
/// Only >1 for keys in BIP389 multipath descriptors.
163163
fn num_der_paths(&self) -> usize { 0 }
164164

165-
/// The associated [`sha256::Hash`] for this `MiniscriptKey`, used in the sha256 fragment.
166-
///
167-
/// [`sha256::Hash`]: bitcoin::hashes::sha256::Hash
165+
/// The type used in the sha256 fragment.
168166
type Sha256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
169167

170-
/// The associated [`hash256::Hash`] for this `MiniscriptKey`, used in the hash256 fragment.
171-
///
172-
/// [`hash256::Hash`]: crate::hash256::Hash
168+
/// The type used in the hash256 fragment.
173169
type Hash256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
174170

175-
/// The associated [`ripemd160::Hash`] for this `MiniscriptKey` type, used in the ripemd160 fragment.
176-
///
177-
/// [`ripemd160::Hash`]: bitcoin::hashes::ripemd160::Hash
171+
/// The type used in the ripemd160 fragment.
178172
type Ripemd160: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
179173

180-
/// The associated [`hash160::Hash`] for this `MiniscriptKey` type, used in the hash160 fragment.
181-
///
182-
/// [`hash160::Hash`]: bitcoin::hashes::hash160::Hash
174+
/// The type used in the hash160 fragment.
183175
type Hash160: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
184176
}
185177

@@ -215,38 +207,46 @@ impl MiniscriptKey for String {
215207
type Hash160 = String;
216208
}
217209

218-
/// Trait describing public key types which can be converted to bitcoin pubkeys
210+
/// Trait describing key types that can be converted to bitcoin public keys.
219211
pub trait ToPublicKey: MiniscriptKey {
220-
/// Converts an object to a public key
212+
/// Converts key to a public key.
221213
fn to_public_key(&self) -> bitcoin::PublicKey;
222214

223-
/// Convert an object to x-only pubkey
215+
/// Converts key to an x-only public key.
224216
fn to_x_only_pubkey(&self) -> bitcoin::secp256k1::XOnlyPublicKey {
225217
let pk = self.to_public_key();
226218
bitcoin::secp256k1::XOnlyPublicKey::from(pk.inner)
227219
}
228220

229-
/// Obtain the public key hash for this MiniscriptKey
230-
/// Expects an argument to specify the signature type.
231-
/// This would determine whether to serialize the key as 32 byte x-only pubkey
232-
/// or regular public key when computing the hash160
221+
/// Obtains the pubkey hash for this key (as a `MiniscriptKey`).
222+
///
223+
/// Expects an argument to specify the signature type. This determines whether to serialize
224+
/// the key as 32 byte x-only pubkey or regular public key when computing the hash160.
233225
fn to_pubkeyhash(&self, sig_type: SigType) -> hash160::Hash {
234226
match sig_type {
235227
SigType::Ecdsa => hash160::Hash::hash(&self.to_public_key().to_bytes()),
236228
SigType::Schnorr => hash160::Hash::hash(&self.to_x_only_pubkey().serialize()),
237229
}
238230
}
239231

240-
/// Converts the generic associated [`MiniscriptKey::Sha256`] to [`sha256::Hash`]
232+
/// Converts the associated [`MiniscriptKey::Sha256`] type to a [`sha256::Hash`].
233+
///
234+
/// [`sha256::Hash`]: bitcoin::hashes::sha256::Hash
241235
fn to_sha256(hash: &<Self as MiniscriptKey>::Sha256) -> sha256::Hash;
242236

243-
/// Converts the generic associated [`MiniscriptKey::Hash256`] to [`hash256::Hash`]
237+
/// Converts the associated [`MiniscriptKey::Hash256`] type to a [`hash256::Hash`].
238+
///
239+
/// [`hash256::Hash`]: crate::hash256::Hash
244240
fn to_hash256(hash: &<Self as MiniscriptKey>::Hash256) -> hash256::Hash;
245241

246-
/// Converts the generic associated [`MiniscriptKey::Ripemd160`] to [`ripemd160::Hash`]
242+
/// Converts the associated [`MiniscriptKey::Ripemd160`] type to a [`ripemd160::Hash`].
243+
///
244+
/// [`ripemd160::Hash`]: bitcoin::hashes::ripemd160::Hash
247245
fn to_ripemd160(hash: &<Self as MiniscriptKey>::Ripemd160) -> ripemd160::Hash;
248246

249-
/// Converts the generic associated [`MiniscriptKey::Hash160`] to [`hash160::Hash`]
247+
/// Converts the associated [`MiniscriptKey::Hash160`] type to a [`hash160::Hash`].
248+
///
249+
/// [`hash160::Hash`]: bitcoin::hashes::hash160::Hash
250250
fn to_hash160(hash: &<Self as MiniscriptKey>::Hash160) -> hash160::Hash;
251251
}
252252

0 commit comments

Comments
 (0)