address: Add generic serde::Serialize for Address

Otherwise a generic `Address<impl NetworkValidation>` is not
serializable.
This commit is contained in:
Steven Roose 2023-04-09 16:55:18 +01:00
parent 814b9917da
commit ed6421c939
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
1 changed files with 3 additions and 6 deletions

View File

@ -748,21 +748,18 @@ where
V: NetworkValidation; V: NetworkValidation;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
struct DisplayUnchecked<'a>(&'a Address<NetworkUnchecked>); struct DisplayUnchecked<'a, N: NetworkValidation>(&'a Address<N>);
#[cfg(feature = "serde")] #[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) } 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")] #[cfg(feature = "serde")]
crate::serde_utils::serde_string_deserialize_impl!(Address<NetworkUnchecked>, "a Bitcoin address"); crate::serde_utils::serde_string_deserialize_impl!(Address<NetworkUnchecked>, "a Bitcoin address");
#[cfg(feature = "serde")] #[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> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: serde::Serializer, S: serde::Serializer,