Swap around the fields in `Address`

There's a restriction that for structs containing unsized types the
unsized type has to be the last field. `Address` is not an unsize type
but we are going to introduce a macro that will assume this order to
work equally well with both sized and unsized types. Thus we swap it
upfront here.
This commit is contained in:
Martin Habovstiak 2025-03-24 14:30:56 +01:00
parent 7a115e3cf1
commit d42364bd9d
1 changed files with 4 additions and 4 deletions

View File

@ -395,7 +395,7 @@ pub enum AddressData {
// The `#[repr(transparent)]` attribute is used to guarantee the layout of the `Address` struct. It // The `#[repr(transparent)]` attribute is used to guarantee the layout of the `Address` struct. It
// is an implementation detail and users should not rely on it in their code. // is an implementation detail and users should not rely on it in their code.
#[repr(transparent)] #[repr(transparent)]
pub struct Address<V = NetworkChecked>(AddressInner, PhantomData<V>) pub struct Address<V = NetworkChecked>(PhantomData<V>, AddressInner)
where where
V: NetworkValidation; V: NetworkValidation;
@ -455,15 +455,15 @@ impl<V: NetworkValidation> serde::Serialize for Address<V> {
/// `Address<NetworkUnchecked>`. /// `Address<NetworkUnchecked>`.
impl<V: NetworkValidation> Address<V> { impl<V: NetworkValidation> Address<V> {
fn from_inner(inner: AddressInner) -> Self { fn from_inner(inner: AddressInner) -> Self {
Address(inner, PhantomData) Address(PhantomData, inner)
} }
fn into_inner(self) -> AddressInner { fn into_inner(self) -> AddressInner {
self.0 self.1
} }
fn inner(&self) -> &AddressInner { fn inner(&self) -> &AddressInner {
&self.0 &self.1
} }
/// Returns a reference to the address as if it was unchecked. /// Returns a reference to the address as if it was unchecked.