Merge rust-bitcoin/rust-bitcoin#1785: Implement serde::Serialize for Address

ed6421c939 address: Add generic serde::Serialize for Address (Steven Roose)
814b9917da address: Add Sync, Send, Sized and UnPin marker traits on NetworkValidation (Steven Roose)

Pull request description:

  With the new rewrite of Address, `serde::Serialize` is only implemented on `Address<bitcoin::address::NetworkChecked>` and `Address<bitcoin::address::NetworkUnchecked>`. But the compiler has no way of knowing that that are all the possible versions of `Address`, so the generic `Address<impl bitcoin::address::NetworkValidation>` doesn't implement `serde::Serialize`.

ACKs for top commit:
  Kixunil:
    ACK ed6421c939
  tcharding:
    ACK ed6421c939

Tree-SHA512: 65e43dff244c94fe08ccb2d985781a2687a1e2db186960a35d4ae89f3b31c5af66892630a3ebaac9cecdc83638487425afa17374869d278648b348869e0ba091
This commit is contained in:
Andrew Poelstra 2023-05-04 21:33:23 +00:00
commit 1abbed2129
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 4 additions and 7 deletions

View File

@ -615,7 +615,7 @@ mod sealed {
/// Marker of status of address's network validation. See section [*Parsing addresses*](Address#parsing-addresses)
/// on [`Address`] for details.
pub trait NetworkValidation: sealed::NetworkValidation {
pub trait NetworkValidation: sealed::NetworkValidation + Sync + Send + Sized + Unpin {
/// Indicates whether this `NetworkValidation` is `NetworkChecked` or not.
const IS_CHECKED: bool;
}
@ -747,21 +747,18 @@ where
V: NetworkValidation;
#[cfg(feature = "serde")]
struct DisplayUnchecked<'a>(&'a Address<NetworkUnchecked>);
struct DisplayUnchecked<'a, N: NetworkValidation>(&'a Address<N>);
#[cfg(feature = "serde")]
impl fmt::Display for DisplayUnchecked<'_> {
impl<N: NetworkValidation> fmt::Display for DisplayUnchecked<'_, N> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.0.fmt_internal(fmt) }
}
#[cfg(feature = "serde")]
crate::serde_utils::serde_string_serialize_impl!(Address, "a Bitcoin address");
#[cfg(feature = "serde")]
crate::serde_utils::serde_string_deserialize_impl!(Address<NetworkUnchecked>, "a Bitcoin address");
#[cfg(feature = "serde")]
impl serde::Serialize for Address<NetworkUnchecked> {
impl<N: NetworkValidation> serde::Serialize for Address<N> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,