Merge rust-bitcoin/rust-bitcoin#2306: Improve address conversion docs

03bfe1d433 Impove rustdoc on assume_checked_ref (Tobin C. Harding)
769809f1f2 Improve the docs on as_unchecked function (Tobin C. Harding)

Pull request description:

  In #1765 we added a couple of new functions.

  - Patch 1: Fix mis-documented function.
  - Patch 2: Do trivial rustdocs fix.

ACKs for top commit:
  apoelstra:
    ACK 03bfe1d433
  Kixunil:
    ACK 03bfe1d433

Tree-SHA512: 5be6b2d288c1f4e9096014acd8618dc84a3ec6f45ae38b5d44ef7f95eccc268021bc8e8435152166606d893d4238b03e59e8f9d4fc67ba9a6c33194f3f54fc40
This commit is contained in:
Andrew Poelstra 2024-01-04 15:55:12 +00:00
commit b63921d625
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 2 deletions

View File

@ -353,8 +353,7 @@ impl<N: NetworkValidation> serde::Serialize for Address<N> {
/// Methods on [`Address`] that can be called on both `Address<NetworkChecked>` and
/// `Address<NetworkUnchecked>`.
impl<V: NetworkValidation> Address<V> {
/// Returns a reference to the unchecked address, which is dangerous to use if the address
/// is invalid in the context of `NetworkUnchecked`.
/// Returns a reference to the address as if it was unchecked.
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
unsafe { &*(self as *const Address<V> as *const Address<NetworkUnchecked>) }
}
@ -630,10 +629,12 @@ impl Address {
/// Methods that can be called only on `Address<NetworkUnchecked>`.
impl Address<NetworkUnchecked> {
/// Returns a reference to the checked address.
///
/// This function is dangerous in case the address is not a valid checked address.
pub fn assume_checked_ref(&self) -> &Address {
unsafe { &*(self as *const Address<NetworkUnchecked> as *const Address) }
}
/// Parsed addresses do not always have *one* network. The problem is that legacy testnet,
/// regtest and signet addresse use the same prefix instead of multiple different ones. When
/// parsing, such addresses are always assumed to be testnet addresses (the same is true for