address: Add `Address::into_unchecked`

Adds an ergonomic way to convert any `Address` (network can be checked
or unchecked) into an `Address<NetworkUnchecked>` without cloning, which
I've found useful in several contexts.
This commit is contained in:
Max Fang 2024-11-18 17:46:35 -08:00
parent c47a41a076
commit e4cf8ebc20
1 changed files with 3 additions and 0 deletions

View File

@ -383,6 +383,9 @@ impl<V: NetworkValidation> Address<V> {
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> { pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
unsafe { &*(self as *const Address<V> as *const Address<NetworkUnchecked>) } unsafe { &*(self as *const Address<V> as *const Address<NetworkUnchecked>) }
} }
/// Marks the network of this address as unchecked.
pub fn into_unchecked(self) -> Address<NetworkUnchecked> { Address(self.0, PhantomData) }
} }
/// Methods and functions that can be called only on `Address<NetworkChecked>`. /// Methods and functions that can be called only on `Address<NetworkChecked>`.