Merge rust-bitcoin/rust-bitcoin#2754: Document CompactTarget order/equality

c8caee2b5e Document CompactTarget order/equality (Tobin C. Harding)

Pull request description:

  Add documentation to the `CompactTarget` type explaining the nuance surrounding order/equality.

  Close: #2110

ACKs for top commit:
  apoelstra:
    ACK c8caee2b5e

Tree-SHA512: c724b31ee620ff08d3c8b547250bc7067f875ef6cf4ce9efa082d5a9cfbd8b92620f86034e58caf573c479ce7aaa89bb7e9fa93dc356524663d3ecf583df3507
This commit is contained in:
Andrew Poelstra 2024-05-22 19:01:31 +00:00
commit d0c1eb138c
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 7 additions and 0 deletions

View File

@ -337,6 +337,13 @@ do_impl!(Target);
///
/// OpenSSL's bignum (BN) type has an encoding, which is even called "compact" as in bitcoin, which
/// is exactly this format.
///
/// # Note on order/equality
///
/// Usage of the ordering and equality traits for this type may be surprising. Converting between
/// `CompactTarget` and `Target` is lossy *in both directions* (there are multiple `CompactTarget`
/// values that map to the same `Target` value). Ordering and equality for this type are defined in
/// terms of the underlying `u32`.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]