Skip to content

Commit d2d3ee9

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 1f7d12c commit d2d3ee9

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/lib.rs

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

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

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

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

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

@@ -216,38 +208,46 @@ impl MiniscriptKey for String {
216208
type Hash160 = String;
217209
}
218210

219-
/// Trait describing public key types which can be converted to bitcoin pubkeys
211+
/// Trait describing key types that can be converted to bitcoin public keys.
220212
pub trait ToPublicKey: MiniscriptKey {
221-
/// Converts an object to a public key
213+
/// Converts key to a public key.
222214
fn to_public_key(&self) -> bitcoin::PublicKey;
223215

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

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

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

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

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

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

0 commit comments

Comments
 (0)